Regex to match string not ending with pattern

后端 未结 4 1528
北恋
北恋 2020-12-06 11:07

I try to find a regex that matches the string only if the string does not end with at least three \'0\' or more. Intuitively, I tried:

.*[^0]{3,}$

4条回答
  •  情话喂你
    2020-12-06 11:51

    What wrong with the no-look-behind, more general-purpose ^(.(?!.*0{3,}$))*$?

    The general pattern is ^(.(?!.* + not-ending-with-pattern + $))*$. You don't have to reverse engineer the state machine like Tim's answer does; you just insert the pattern you don't want to match at the end.

提交回复
热议问题