After looking through the answers that are already on StackOverflow regarding this issue, I settled with the most accurate one I could find:
Java regex: Negative lookahead
I went over to gskinner and tested it. I put /foo/(?!.*\\bbar\\b).+ in the pattern input box and the following in the regex match text area:
/foo/abc123doremi
/foo/abc123doremi/bar/def456fasola
Gskinner recognised both of these as matches though so clearly either Gskinner is wrong or the regex pattern above isn’t correct. Any thoughts?
You are looking for
\bbar\bwhile your text contains/bar/.What you meant is probably
\bbar\b(i.e./foo/(?!.*\bbar\b).+)Note that “duplicate the
\” is only required inside of Java String literals. That makes writing regexs in Java a bit of a pain.