【问题标题】:regular expression: match everything but single forward- and double backslashes正则表达式:匹配除单个正斜杠和双反斜杠之外的所有内容
【发布时间】:2015-06-09 23:19:10
【问题描述】:

"[^/]*" 对正斜杠很好用,但是"[^/\\\\\\\\]" 显然不能在集合中使用。

除了两个连续的反斜杠之外,我如何匹配所有内容?

【问题讨论】:

    标签: python regex python-3.x


    【解决方案1】:

    最简单的方法是使用negative lookahead 排除这两种模式。

    re.match(r'(?!.*/|.*\\\\)', string)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      相关资源
      最近更新 更多