fork download
  1. import re
  2. text = '''146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize HTTP/1.1" 302 4622
  3. 197.109.77.178 - kertzmann3129 [21/Jun/2019:15:45:25 -0700] "DELETE /virtual/solutions/target/web+services HTTP/2.0" 203 26554'''
  4. pattern = r'''(?P<host>\d{1,3}(?:\.\d{1,3}){3})
  5. (\ -\ )
  6. (?P<user_name>[a-z]{1,100}\d{4}|-)
  7. (\ \[)(?P<time>\d{2}/[A-Za-z]{3}/\d{4}:\d{2}:\d{2}:\d{2}\ -\d{4})
  8. (\]\ ")
  9. (?P<request>.+)
  10. (")'''
  11. for item in re.finditer(pattern,text,re.VERBOSE):
  12. print(item.groupdict()) # We can get the dictionary returned for the item with .groupdict()
Success #stdin #stdout 0.03s 9632KB
stdin
Standard input is empty
stdout
{'host': '146.204.224.152', 'user_name': 'feest6811', 'time': '21/Jun/2019:15:45:24 -0700', 'request': 'POST /incentivize HTTP/1.1'}
{'host': '197.109.77.178', 'user_name': 'kertzmann3129', 'time': '21/Jun/2019:15:45:25 -0700', 'request': 'DELETE /virtual/solutions/target/web+services HTTP/2.0'}