Having a slight regex problem. I wrote to following code to check if a word is contained within a String.
boolean matches = Pattern.matches("\\b" + Pattern.quote(item.name) + "\\b", nap.code);
item.name will be something like “half”
nap.code will be something like “int halfOfFour() { return half(4); }”
Yet, my pattern match returns false… What am I doing wrong here?
Also… Is there anyway to make this return false if the word is contained within a string?
I think the pattern match will match the whole string not just a part of it. so prefix with .* and postfix with .* or something.
use pattern and matches separately and then use “find()” in matcher to find submatches