Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regex: Custom find all using re.search 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 [re.search(expression, string).groups() for string in strings
if re.search(expression, string)]
find_all(find_events, logs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment