I'd like my Regex to match "foo" and "bar", but not if "foo" or "bar" start with "a ", "an ", or "the ".
foo
and bar
are not guaranteed to be at the start or end of a string.
Example matches:
"end of Foo." [1 Match: Foo]
"end of bar." [1 Match: bar]
"The foo and bar" [1 Match: bar]
"foo bar" [2 Matches: foo, bar]
Example no matches:
"foobar"
"foofoo"
"the foo"
"a bar"
"andbar"
"the foo goes to a bar."
I guess I may have to do a negative lookbehind? If so, could this be converted into a negative lookahead for portability with JS?
I've tried
/(\bfoo\b|\bbar\b)(?!the|a(n)?)/igm
but this doesn't work.
Many thanks.