Given the following text (note the newline character):
foo bar foo5 bar foo-bar foo qux quux\n foo
I wish to get all matches for foo
and qux quux
, expect in the cases any of these appears next to a digit, letter, or underscore, i.e.
foo bar foo5 bar foo-bar foo qux quux\n bar foo
Using the following regex:
(?:\W)(foo|qux quux)(?:\W|$)
I get a match for all desired occurrences of foo
:
foo bar foo5 bar foo-bar foo qux quux\n bar foo
The problem is that I don't get a match for qux quux
, since the single whitespace that precedes it has already been matched as a non-capturing group (?:
) of the 3rd match:
...
Match 3
Full match: " foo "
Group 1 : "foo"
...
How can I also get qux quux
?
NOTE: I understand that by inserting 2 whitespaces between foo
and qux quux
would make my regex work, but this is silly.