Created
April 6, 2020 16:14
-
-
Save ychennay/7b85d71840adaa51d95bf5c362759cc9 to your computer and use it in GitHub Desktop.
Regex: Custom find all using re.search and groups()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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