Skip to content

Instantly share code, notes, and snippets.

@ei-grad
Last active November 18, 2015 19:40
Show Gist options
  • Save ei-grad/577567d8903a6815b176 to your computer and use it in GitHub Desktop.
Save ei-grad/577567d8903a6815b176 to your computer and use it in GitHub Desktop.
Regular expression to parse apache combined log in python
import re
apache_combined = re.compile(
'(?P<clientip>[\d\.]+) (?P<ident>\S+) (?P<auth>\S+) '
'\[(?P<timestamp>.*?)\] '
'"(?P<verb>\S+) (.*) HTTP/(?P<httpversion>\d\.\d)" '
'(?P<response>\d+|-) (?P<bytes>\d+|-)'
'( "(?P<referrer>.*?)")?'
'( "(?P<agent>.*)")?'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment