Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created April 6, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ychennay/7b85d71840adaa51d95bf5c362759cc9 to your computer and use it in GitHub Desktop.
Save ychennay/7b85d71840adaa51d95bf5c362759cc9 to your computer and use it in GitHub Desktop.
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