String negation using regular expressions

后端 未结 2 1505
青春惊慌失措
青春惊慌失措 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.

提交回复
热议问题