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 an example of what should happen:
this should be highlighted, and
same with this. but any sentence
that has the word
foobar
shouldnt be, and same for any regular
sentence with foobar <-- like that
foobar beginning a sentence should invalidate
the entire sentence, same with at the end foobar
only foobar, and nothing else of the sentence
more words here more irrelevant stuff to highlight
and nothing of the key word
what about multiple foobar on the same foobar line?
And what should be matched, would look something like this:
The best I could get is /\b(?!foobar)[^\n]+\n?/g
which works if the word foobar is alone on it's own separate line formatted like this:
not foobar
foobar (ignored)
totallynotfoobar
nobar
foobutts
foobar (ignored)
notagain
And the rest is matched... but this is not what I want.
So my question is, how would I accomplish the original example? Is it even possible?