【发布时间】:2014-01-26 21:00:33
【问题描述】:
我有以下正则表达式(更新):
([0-9]{2}/[a-zA-Z]{3}/[0-9]{4})(.+)(GET|POST)\s(http://|https://)([a-zA-Z-.][a-zA-Z0-9+\.[a-zA-Z0-9-.]+)(\.)([a-zA-Z0-9]+)([\.:/\s]).+?"\s200
我还从长服务器日志中摘录了以下几行(已更新):
218.5.192.147 - - [14/Mar/2004:02:31:06 -0500] "GET http://searchanytime.com" 200 - "-" "-"
202.101.150.100 - - [12/Mar/2004:21:18:55 -0500] "GET http://nationalwholesalellc.com" 200 114887 "-" "-"
这些线路按计划工作:
220.173.17.142 - - [09/Mar/2004:23:32:13 -0500] "POST http://www.canada44.ca/ HTTP/1.1" 200 27095 "http://www.so123.com" "Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)"
212.160.136.163 - - [10/Mar/2004:01:01:46 -0500] "GET http://www.6seconds.org/ HTTP/1.0" 200 51937 "http://www.helavasearch.com/cgi-bin/search.cgi?username=amundii&keywords=parenting" "Mozilla/4.0 (compatible; MSIE 4.0; Windows 98)"
218.72.85.59 - - [10/Mar/2004:01:05:13 -0500] "GET http://hpcgi1.nifty.com/trino/ProxyJ/prxjdg.cgi HTTP/1.1" 200 2221 "-" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
在几乎所有情况下,第 7 组都是我的顶级域(com、cn、org 等)。但是,对于具有 .com" 而不是 .com HTTP/1.1" 的行,它不起作用并将第 7 组返回为 "searchanytime" 而不是 "com"
我一直在使用 www.regexr.com
【问题讨论】:
-
试试这个:txt2re.com。还将日志文件示例中的 URL 清理为假人。
-
感谢我更新了我的帖子
标签: python regex apache search findall