我需要一个正则表达式,用于在Java程序中解析Apache错误文件,例如:
然而,它似乎无法匹配以下字符串:
请注意,如果在方括号中包含客户端关键字,那么将所有数据作为单个组接收也是可以的。
[Thu Sep 27 12:08:18 2012] [error] [client 151.10.158.10] File does not exist: /srv/www/htdocs/pad/favicon.ico
[Thu Oct 04 17:02:42 2012] [error] [client 151.10.1.10] File does not exist: > /srv/www/htdocs/pad/favicon.ico
[Wed Oct 17 10:16:40 2012] [error] [client 151.10.14.60] File does not exist: /srv/www/htdocs/pad/sites/all/modules/fckeditor/fckeditor/editor/userfiles, referer: http://pad.sta.uniroma1.it/sites/all/modules/fckeditor/fckeditor/editor/fckeditor.html?InstanceName=edit-body&Toolbar=DrupalFull
我已经尝试了几种解决方案(其中一些以前在stackoverflow上报告过),似乎最有效的是:
^(\[[\w:\s]+\]) (\[[\w]+\]) (\[[\w\d.\s]+\])?([\w\s/.(")-]+[\-:]) ([\w/\s]+)$
然而,它似乎无法匹配以下字符串:
[Thu May 17 22:41:54 2012] [error] [client 118.238.211.206] Invalid URI in request GET :81/phpmyadmin/scripts/setup.php HTTP/1.1
我该如何修复它?
编辑 我检查了所有提出的解决方案,虽然可以提高匹配行数,但它们仍然无法处理以下情况:
[Fri Jul 15 00:24:41 2011] [error] [client 219.12.35.141] script '/srv/www/htdocs/pad2/scripts/setup.php' not found or unable to stat
[Mon May 28 18:43:25 2012] [error] [client 88.110.28.25] Invalid URI in request GET HTTP/1.1 HTTP/1.1
请注意,如果在方括号中包含客户端关键字,那么将所有数据作为单个组接收也是可以的。
[...]
组和行尾吗? - Sergii Lagutin