How can I find all words that have no specific character before?
For example, if I want to match all apple
, which have no any character b
before it, how should I do?
dolphin elephant apple star <-- Matched
dog cat apple banana <-- Matched
map banana apple dog <-- Unmatched (Since there's ab
before theapple
)
map apple banana apple cat <-- The firstapple
matched, but the second one unmatched.
map apple banana apple banana apple <-- Only the firstapple
matched, others are unmatched.
map apple dog apple banana apple banana apple <-- The firstapple
and the secondapple
matched, others are unmatched.
Here's my try:
/(?<!.*b.*)apple/g
And of course, the regex above is invalid, since the quantifier (asterisk in this case) inside the lookbehind makes it non-fixed width. So how should I do to solve this problem?