有輕微的正則表達式問題。我寫了下面的代碼來檢查一個字是否包含在一個字符串中。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