有轻微的正则表达式问题。我写了下面的代码来检查一个字是否包含在一个字符串中。Java正则表达式不起作用
boolean matches = Pattern.matches("\\b" + Pattern.quote(item.name) + "\\b", nap.code);
item.name将会像 “半壁江山” nap.code将会像 “INT halfOfFour(){回流半部(4);}”
然而,我的模式匹配返回false ...我在这里做错了什么?
另外...有没有反正,如果这个单词包含在一个字符串中,这个返回假?
当然,我假设你不想使用字符串包含或indexOf/lastIndexOf – 2012-08-02 09:24:49
'System.out.println(“int halfOfFour(){return half(4);}”。 match(“。* \\ bhalf \\ b。*”));' - > true – 2012-08-02 09:27:26
“testfunc passing(){ int halfOfFour = half(4); assert(halfOfFour == 2,”The laws of (“。* \\ b”+ Pattern.quote(“half”)+“\\ b。*”); 仍然导致错误... – 2012-08-02 10:22:06