I am trying to look for specific phrase inside large text, but the phrase may contain characters like “[“, “(“, “*”, … like “name1 (name2”, but it causes an invalid exception when looking for it. Here is my code :
Pattern myPattern = Pattern.compile( "\\b" + phrase + "\\b" ); // Exception
Matcher myMatcher = myPattern.matcher( largeText );
I have tried to use quote(…) to fix such characters but it didn’t work :
phrase = Pattern.quote( phrase );
How can i fix this to allow such characters ?
Pattern.quote(phrase)works just fine:prints: