Regular Expressions 101

Community Patterns

Apache/Nginx Logs parsing

1

Regular Expression
PCRE (PHP <7.3)

/
((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))[, ].{1,}\[([0-3][0-9]\/\w{3}\/[0-9]{4}):([0-2][0-9]:[0-5][0-9]:[0-5][0-9]) ((?:\+|\-)[0-9]{4})\].{1,}"(GET|POST|HEAD|PUT|DELETE|TRACE|CONNECT) ([\/\w\.\-\?\_\=\*\$\%\:]+).{1,}" (\b\d{3}) (\d+|-) "((?:(?:http(?:s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,24}\b[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)|-)" "([^"]+)" "([^"]+)"$
/

Description

Log Format - combined + cookie at the end. Pattern Desc - combined for all groups.

Submitted by Samuil Dichev - 9 years ago