Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Regex: Custom find all using and groups()
import re
file = open("SSH_2k.log.txt")
logs = file.readlines() # returns a list of strings
find_events = r'sshd\[(24200|24206)\]: (.+)' #regex to parse out event messages from process ID 24200 or 24206
def find_all(expression, strings):
return [, string).groups() for string in strings
if, string)]
find_all(find_events, logs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment