开发者

Regex ignore succeeding word occurence

开发者 https://www.devze.com 2022-12-08 07:58 出处:网络
If i have these strings: banana not included. apple included. banana, apple included. the regex below returns a match on both strings but I don\'t wan开发者_开发知识库t a match on the first string

If i have these strings:

banana not included. apple included.
banana, apple included.

the regex below returns a match on both strings but I don't wan开发者_开发知识库t a match on the first string

banana.*(?<!(\bnot ))inc(\.|luded)?

What am I missing in my regex to achieve my desired result.

Thanks!


It's hard to tell from only two examples, but perhaps this is what you want?

banana(?!.*\bnot\b).*\binc(\.|luded)?


I don't have a better solution than Laurence, but to answer the why portion of your question, I believe that the .* has already consumed the not that your lookbehind is looking for.

0

精彩评论

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

关注公众号