Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- template = "(?P<DATE>\d{4}-\d{2}-\d{2}) (?P<TIME>\d\d:\d\d:\d\d) (?P<MODULE>[a-z0-9_]*.py) (?P<LOG_MESSAGE>.*)"
- example = "2014-03-01 15:33:43 my_module.py some test log message"
- matches = re.search(template, example)
- date = matches.group('DATE')
- time = matches.group('TIME')
- module = matches.group('MODULE')
- message = matches.group('LOG_MESSAGE')
- print("DATE:", date, "TIME:", time, "MODULE:", module, "MSG:", message)
Advertisement
Add Comment
Please, Sign In to add comment