【问题标题】:Inverting a regex that includes two expressions反转包含两个表达式的正则表达式
【发布时间】:2014-11-05 12:34:02
【问题描述】:

我有一个正则表达式,它匹配所有不包含't's 或至少包含一个不在序列'th' 中的't' 的行。我想反转它,以便它只匹配那些包含 'th' 但不包含其他 't' 的行。

^.*?t(?!h).*?$|^[^t]+$

这是一个示例输入。表达式 currents 匹配所有带 + 号的行。

thought +1
though -1
without +2
within -2
tenth +3
thoth -3
tents +4
sample +5
thirteenth +6

如何编写带有负前瞻的表达式,使其仅匹配带有 - 符号的行?

【问题讨论】:

    标签: regex regex-negation regex-lookarounds


    【解决方案1】:

    这应该可行:

    ^(?!.*t[^h]).*th.*$
    

    在这里测试:http://regex101.com/r/jS5fW8/1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      相关资源
      最近更新 更多