$re = '~^(?:(?<network_srcIpv4>(?:[0-9]{1,3}\.){3}[0-9]{1,3})|(?<network_srcIpv6>[:\-0-9a-fA-F]+?)|(?<network_srcHost>.+?)) - (?:-|(?<user_username>.+)) \[(?<time>.*)\] \"(?<application_cmd>(?<application_http_method>[A-Z]+)\s(?:(?<application_proto>.*?)://)?(?<network_fqdn>[^/]*?)(?:\:(?<network_dstPort>\d+))?(?<file_path>/.*?)?(?:\?(?<application_http_queryString>.*?))?(?: HTTP/(?<application_http_version>[0-9\.]+)?))\" (?<application_http_status>\d+) (?<application_len>\d+) (?:"(?:-|(?<application_http_referrer>.*))")? (?:"(?:-|(?<application_http_userAgent>.*))")$~m';
$str = '218.1.111.50 - - [13/Mar/2005:10:36:12 -0500] "GET http://www.yahoo.com/ HTTP/1.1" 403 2898 "-" "Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)"
24.23.244.160 - - [13/Mar/2005:13:48:40 -0500] "GET /scripts/..%25%35%63../winnt/system32/cmd.exe?/c+dir HTTP/1.0" 404 1041 "-" "-"';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php