Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?:-|(?P<real_ip>[\-\da-f.:, ]+)) - (?<remote_user>\S+) \[(?<timestamp>[^\]]+)\]\s+"(?:\-|(?<request>\w+) (?<request_uri>[^ \?]+)(?:\?(?<request_uri_query>[^ ]*))? (?<request_version>[\w\/\.]+))"\s+(?P<status>[1-9]\d{2})\s+(?P<body_bytes_sent>\d+)\s+"(?<http_referer>[^"]+)"\s+"(?<http_user_agent>[^"]+)"\s+"(?P<remote_ip>[\da-f.:]+)" (?:\-|(?P<upstream_response_time>\d+(?:.\d+)?))\s+(?P<request_time>\d+(?:.\d+)?) (?P<pipe>[\.p])
/
gm

Description

log_format timed  '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$remote_addr" '
                  '$request_time $upstream_response_time $pipe';
Submitted by Pei-Tang Huang - 2 years ago