-3
String stre = "da shi+ jia";
profaneWord= "shi+";
boolean flag = isContain(stre, profaneWord);
private static boolean isContain(String source, String subItem) {
    String pattern = subItem;
    String pat = Pattern.quote(pattern);
    System.out.println("pattern quote example  " + pat);
    Pattern p = Pattern.compile("\b"+pat+"\b");
    System.out.println("pattern quote example  " + p.toString());
    Matcher m = p.matcher(source);
    return m.find();
}

pattern quote example \Qshi+\E pattern quote example \Qshi+\E false

Expected : true

I am using java 7 .

Robert Ravikumar
  • 912
  • 2
  • 11
  • 29

1 Answers1

0

Word boundary escape is \\b not \b.

Pattern.compile("\\b"+pat+"\\b");
Leo Aso
  • 11,898
  • 3
  • 25
  • 46