瀏覽代碼

fixed issue, one error still

Tommy Rogers 6 年之前
父節點
當前提交
26e5a0e234
共有 1 個檔案被更改,包括 4 行新增4 行删除
  1. 4
    4
      src/main/java/HamletParser.java

+ 4
- 4
src/main/java/HamletParser.java 查看文件

@@ -39,14 +39,14 @@ public class HamletParser {
39 39
     }
40 40
 
41 41
     public String changeWord(String search, String replace){
42
-        Pattern patt = Pattern.compile("^" +search + "", Pattern.CASE_INSENSITIVE);
42
+        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
43 43
         Matcher m = patt.matcher(hamletData);
44
-        return m.replaceAll(replace);
44
+        return m.replaceAll("" + replace + "");
45 45
     }
46 46
 
47
-    public int findWord(CharSequence hamletData ,String search) {
47
+    public int findWord(String hamletData ,String search) {
48 48
         int count = 0;
49
-        Pattern patt = Pattern.compile("^" +search + "", Pattern.CASE_INSENSITIVE);
49
+        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
50 50
         Matcher m = patt.matcher(hamletData);
51 51
      while (m.find())
52 52
             count++;