【问题标题】:Regex with negation for extracting web link带有否定的正则表达式用于提取网络链接
【发布时间】:2020-01-21 16:38:57
【问题描述】:

我有一个文本片段:

.....https://www.one.com/privacy/\............http://two.com/terms/'.............https://three.com/pricing/\..........https://four.com/widget/wg74ythx;.........http://five.com/pricing .........

我提取网页链接的代码: link = re.compile(r'https?://(\w.*?)(\\|;|\'|\s)')

但我需要从我的结果中排除所有带有“隐私”或“小部件”字样的链接。 我被困在这里,我需要社区的帮助。

【问题讨论】:

  • 你能检查一下这些词的结果吗? if 'privacy' in url:...

标签: python python-3.x regex-negation


【解决方案1】:

如果您不需要编译对象,您可以执行类似的操作

s = mystring urls = [url[0] for url in re.findall(r'https?://(\w.*?)(\\|;|\'|\s)',s) \ if not re.search('privacy|widget',url[0])]

【讨论】:

    猜你喜欢
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多