Browse Source

fixed issue, one error still

Tommy Rogers 6 years ago
parent
commit
26e5a0e234
1 changed files with 4 additions and 4 deletions
  1. 4
    4
      src/main/java/HamletParser.java

+ 4
- 4
src/main/java/HamletParser.java View File

@@ -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++;