Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Regex中查看Web服务器日志? 解释_Python_Regex - Fatal编程技术网

Python 在Regex中查看Web服务器日志? 解释

Python 在Regex中查看Web服务器日志? 解释,python,regex,Python,Regex,在我的日志中,我有许多这样的行: "[14/Oct/2014:13:02:15 +0200]","70","-","192.168.1.1","/API-1.2/testeo_keyword/vcn,ge/channel,rateber/site,bla_.de/keyword,null/px2.js","?ts=0.3054514767395726", "200","+", "http://www.bla.de/Arzt/Baden-W%C3%BCrttemberg/328-Heidelber

在我的日志中,我有许多这样的行:

"[14/Oct/2014:13:02:15 +0200]","70","-","192.168.1.1","/API-1.2/testeo_keyword/vcn,ge/channel,rateber/site,bla_.de/keyword,null/px2.js","?ts=0.3054514767395726", "200","+", "http://www.bla.de/Arzt/Baden-W%C3%BCrttemberg/328-Heidelberg/Neurochirurgie/","Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50527; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; MS-RTC LM 8)","-"0/hurlau,superman;tile,4;status,0/pxl.js","?ts=0.3001205851715877", "200","+", "http://www.super.de/news/audio-video/carl-zeiss-praesentiert-3d-brille-100-euro-742545.html","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0","-"
捕获什么? 从n-2nd字段(带有URL的字段)中,我需要捕获域名,对于每个
domain name=super.de
,我需要收集整个URL

我有什么? 我有一个正则表达式:我设法捕获了我所需要的一切,但我这样做是正确的吗((匹配)匹配)。稍后,我需要在domainname=“super.de”所在的任何地方收集整个URL。此外,www是可选的。注意:第一个URL(www.bla.de)需要忽略

((?:www\.)?super\.de[^"]*)
您可以尝试使用
super.de
作为域获取url。请参阅演示。使用
re.findall
re.search


我认为可以简化复杂的正则表达式,只需查看您捕获每个域的URL的需求
name=super.de

https?:\/\/(?:www\.)?super.de[^"]+(?!.*?super\.de)

几乎完美,但如果超级发生在n-2组以外的其他地方,例如第5组(它发生),这也会捕获整个错误组。我只需要它来匹配n-2nd组,其中n=最后一组。@sirbenji如果这能与regex101.com/r/cU3sY9/2一起使用,那就太好了。如果可能的话,我还需要它比前瞻更有效,因为我需要抓取千兆字节。我已经为您的示例提供了一个工作演示,即如果您想避免前瞻的话然后我认为为了提高效率,最好通过逗号分割来预处理数据,并且只在结果数组的特定元素上应用非前瞻性正则表达式。好的,如果我们在开始和结束处添加两个parantesse,您的示例将起作用-简化正则表达式的另一种方法是:
^(?:[^”]*“[^”]*”[^”]*{14}”[^”]*”(https?:\/\/(?:www\)?super.de[^“]+)
请参阅此演示: