首页 > 解决方案 > 正则表达式查找所有字符串和介于两者之间的任何字符的链接

问题描述

我有一个这样的文本摘录(原始文本很长,超链接交错排列):

... <div> <a href=\n=3D"https://www.wonder.com/alerts/remove" style=3D"text-decoration:none;color:#427fed">Unsu=\nbscribe</a> <span style=3D"padding:0px 4px 0px 4px;color:#252525">|<a href=3D"https:=\n//www.wonder.com/url?rct=3Dj&amp;sa=3Dt&amp;></span> =\n<a href=3D"https://www.wonder.com/alerts?source=3Dalertsmail&amp;hl=3Den&=\namp;gl=3DIN&amp;msgid=3DMTA2MzYwOTAxMTQ5NzI4MTc3MTE" style=3D"text-decorati=\non:none;color:#427fed"> View all your alerts </a> </div> </td> </tr> <tr> <=\ntd style=3D"padding:6px 10px 0px 0px;font-family:Arial"> <a href=3D"https:/=\n/www.wonder.com/alerts/feeds/065638/93686812" styl=\ne=3D"text-decoration:none;color:#427fed">...

我正在尝试提取此超链接(不一定是最后一个):https:/=\n/www.wonder.com/alerts/feeds/065638/93686812

我不知道 '=' 将出现在链接中的什么位置。所以尝试使用这样的积极前瞻:

re.match(r'(?=\=)\"https(.*).*\"', text)

这没有帮助。建议请。

另外,有没有一种方法可以定义一个存在字符串的列表,然后匹配一个包含所有这些字符串的字符串?我看到了几篇关于匹配列表中的任何内容的帖子,而不是全部。我试图寻找一种类似(https)&(wonder)&(alerts)&(feeds)但运气不佳的模式。

标签: pythonregexpython-3.x

解决方案


这对我有用:

(\"https([^\"])*\d+\")

推荐阅读