开发者

Can i exclude a word in my pattern?

开发者 https://www.devze.com 2022-12-23 14:28 出处:网络
I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is there a way to do something like

I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is there a way to do something like

ab(^hi)+def
开发者_StackOverflow中文版

which will exclude the word hi causeing ab_blah_hi_blah_def to fail? but not ab_blah_h_i_blah_def


You can use a negative lookahead to do something like this. The pattern (?!foobar). matches every character, except the f in "foobar".

So to match every word but "hi", you could use ^((?!hi)\w)+$.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号