I unsuccessfully try to find a solution to this problem:
Find a Java regular expression that can recognize a string containing one word and not contain another word .
To be more clear, as an example, let him check if my sentence contains a “method” and does not contain “effective” whole words (which means that it should not be part of another word). The regular expression repeater should return, for example:
This method was efficient. false (contains "method", but contains "efficient")
This method was unefficient. true (cont. "method" doesn't cont. "efficient")
This method was simple. true (cont. "method" doesn't cont. "efficient")
This routine is efficient false (cont. "efficient" but no "method")
What I have tried so far is at least a closer solution.
( method )(?!.*efficient.*) Almost there, but "unefficient" also triggers.
( method )(?!.* efficient .*) No. Now " method " doesn't trigger anymore.
((.*method.*)(?!.*efficient.*)) No. the absence of "efficient" doesn't trigger.
So this is a problem of exact word matching. So I also tried first:
(.*\bmethod\b.*)(?!.*efficient.*)
Also, so as not to depend on spaces, to associate every word. But nothing. I tried almost the whole day and it hurt.
http://www.regular-expressions.info/refquick.html
-,
http://regexpal.com/
.
!
.