2014-04-06 155 views
0

工作 我使用正则表达式找到一个.txt文件蟒蛇正则表达式

blahblah'url=:'http://link.com/=tag/blahblah'url=:'http://link2.com/=tag' 

我的正则表达式看起来像所有的链接:

links = re.findall(r"url=:'http://.+?=tag", source) 

结果:

url=:'http://link.com/=tag/, url=:'http://link2.com/=tag' 

回答

2

使用一个捕获组你想要的模式返回:

links = re.findall(r"(url=:'http://.+?=tag)", source) 

演示:

>>> import re 
>>> source = "blahblah'url=:'http://link.com/=tag/blahblah'url=:'http://link2.com/=tag'" 
>>> re.findall(r"(url=:'http://.+?=tag)", source) 
["url=:'http://link.com/=tag", "url=:'http://link2.com/=tag"] 
+0

@devnull:感谢您的指正。 –