Regular Expressions 101

Community Patterns

Apache user agent regex

0

Regular Expression
PCRE2 (PHP >=7.3)

/
([^(]+)?(\([^)]+\))?([^(]+)?(\([^)]+\))?(.*)
/
gm

Description

This regex groups data for easy parsing based on typical Apache user agent logs. The regex will never fail; it matches anything, even if user agent is atypical. Whitespaces on matches will need to be cleaned programmatically.

Submitted by: Dennis Faas https://www.infopackets.com

Submitted by anonymous - a year ago