Java Regex Negative Lookahead

After looking at the answers already in StackOverflow on this issue, I decided to find the most accurate result:

Java regex: Negative lookup

I switched to gskinner and tested it. I put /foo/(?!.*\\bbar\\b).+ in the template input field and the following in the regular expression matching text area:

/ Foo / abc123doremi

/ Foo / abc123doremi / bar / def456fasola

Gskinner recognized both of them as coincidences, although it is so clear that either Gskinner is erroneous or the regular expression pattern above is incorrect. Any thoughts?

+4
source share
1 answer

You are looking for \bbar\b , while your text contains /bar/ .

What do you mean, probably \bbar\b (i.e. /foo/(?!.*\bbar\b).+ )

Note that "duplicate \ " is only required inside Java String literals. This makes writing regular expressions a bit painful in Java.

+6
source

All Articles