I understand that you can use Pattern.quote to escape characters within a string that is reserved by regex. But I do not understand why the following is not working:
String s="and this)";
String ps = "\\b("+Pattern.quote(s)+")\\b";
//String pp = Pattern.quote(pat);
Pattern p=Pattern.compile(ps);
Matcher mm = p.matcher("oh and this) is");
System.out.println(mm.find()); //print false, but expecting true?
When String s= "and this)
is changed to String s="and this
, i.e., no )
, it works. How should I change the code so with ")" it also works as expected?
Thanks