【问题标题】:Python regex for detecting all the urls excluding certain domains用于检测除某些域之外的所有 url 的 Python 正则表达式
【发布时间】:2015-09-29 19:18:34
【问题描述】:

我有这个可以检测所有 url 的 python 正则表达式:

r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)'

但我需要从检测中排除 youtube 和 vimeo url。我能做什么?

【问题讨论】:

    标签: python regex url


    【解决方案1】:

    您可以使用negative look-ahead

    (http[s]?://(?!youtube|vimeo)(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)
    

    查看演示https://regex101.com/r/jB7tN3/1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      相关资源
      最近更新 更多