Regex to parse your default nginx access logs
I've written a not that complex regex with groups to parse the log easly
(?P<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - - \[(?P<dateandtime>\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})\] ((\"(GET|POST) )(?P<url>.+)(http\/1\.1")) (?P<statuscode>\d{3}) (?P<bytessent>\d+) (["](?P<refferer>(\-)|(.+))["]) (["](?P<useragent>.+)["])
The named capturing groups are python style :)
here are other 2 types of groups that work for other languages.
(?'name'...)
(?<name>...)
Modify as you see fit.
Written by Nikola Sivkov
Related protips
2 Responses
Thanks! It helps me for https://gist.github.com/KhodeN/8052013
over 1 year ago
·
thanks
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#