In continuation of a previous question I had:
So I'm in a situation where I MUST use only regex to select everything but a specific word. For the purposes of example, the word will be 'foobar'. This is what should happen:
The original regex that works with this example is /\W*\b(?!foobar).+?\b\W*/g
.
The problem with that regex is that things like foobartest
and foobar1234
with anything after foobar, is ignored along with the foobar. This is not what I want. The test
and 1234
should not be getting ignored, however the starting foobar
should, it shouldn't disclude the entire word because it wasn't exactly foobar. The only scenario where this should occur is with something like foobarfoobar
, where it ignores both foobars as intended. Everything else should be matched without exception.
The supposed duplicate does not accomplish what I'm requesting.
One last thing to note is that I can not use lookbehind, only lookahead. Is there any way to achieve what I want? Thanks!