提取所有的URL我有这样正则表达式从字符串
http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/
一个字符串,我想所有的URL/webaddress提取到一个数组。例如
urls = ['http://example.com/path/topage.html','http://twitter.com/p/xyan',.....]
这里是我的方法,没有工作。
import re
strings = "http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/"
links = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', strings)
print links
// result always same as strings
这应该对您有所帮助:http://regex101.com。你可以在那里玩你的正则表达式,看看你的问题可能是什么。 – idjaw
你必须保持领先'http(s)'? – Bahrom
是的,我将不得不@Bahrom –