fork download
  1. import re
  2.  
  3. text = """2023-05-27 / 23:06:31 Computer account added/changed/deleted. medium ANONYMOUS LOGON PC-CR5$ SRVDC2 ACME 1
  4. 2023-05-27 / 23:28:08 Computer account added/changed/deleted. medium ANONYMOUS LOGON SRVXAP02$ SRVDC2 ACME 1
  5. 2023-05-28 / 02:24:29 User account locked out multiple login errors high SRVDC2$ john.smith.admin SRVDC2 \\\\NECBROWSER 1
  6. 2023-05-28 / 05:01:48 Computer account added/changed/deleted. medium ANONYMOUS LOGON SRVNPS01$ SRVDC1 ACME 1
  7. 2023-05-28 / 06:38:57 Computer account added/changed/deleted. medium ANONYMOUS LOGON VD-OPERATOR1$ SRVDC1 ACME 1"""
  8.  
  9. pattern = re.compile(r'''
  10. \d{2}:\d{2}:\d{2}\s+
  11. (.*?)
  12. \s(?:medium|high|low|critical)
  13. ''', re.VERBOSE)
  14.  
  15. messages = [match.group(1) for match in pattern.finditer(text)]
  16. print(messages)
Success #stdin #stdout 0.03s 9652KB
stdin
Standard input is empty
stdout
['Computer account added/changed/deleted.', 'Computer account added/changed/deleted.', 'User account locked out multiple login errors', 'Computer account added/changed/deleted.', 'Computer account added/changed/deleted.']