Last Updated: February 25, 2016
·
17.61K
· aviatrix

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.

2 Responses
Add your response

over 1 year ago ·

thanks

over 1 year ago ·