【发布时间】:2013-03-06 14:36:01
【问题描述】:
我有一个正则表达式,它在某些文本中查找 url,例如:
my_urlfinder = re.compile(r'\shttp:\/\/(\S+.|)blah.com/users/(\d+)(\/|)')
text = "blah blah http://blah.com/users/123 blah blah http://blah.com/users/353"
for match in my_urlfinder.findall(text):
print match #prints an array with all the individual parts of the regex
如何获取整个网址?目前 match 只是打印出匹配的部分(我需要其他的东西)......但我也想要完整的 url。
【问题讨论】:
-
最简单的方法是添加一组额外的括号,将整个正则表达式括起来。然后你把它和零件一起搞定!