String negation using regular expressions

后端 未结 2 1495
青春惊慌失措
青春惊慌失措 2020-12-08 19:18

Is it possible to do string negation in regular expressions? I need to match all strings that do not contain the string \"..\". I know you can use ^[^\\

相关标签:
2条回答
  • 2020-12-08 19:52

    You can use negative lookaheads:

    ^(?!.*\.\.).*$
    

    That causes the expression to not match if it can find a sequence of two periods anywhere in the string.

    0 讨论(0)
  • 2020-12-08 19:52
    ^(?:(?!\.\.).)*$
    

    will only match if there are no two consecutive dots anywhere in the string.

    0 讨论(0)
提交回复
热议问题