JDK自帶的有趣的例子java
Pattern p = Pattern.compile("cat\\b"); Matcher m = p.matcher("one cat two cats in the yard"); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, "dog"); } m.appendTail(sb); System.out.println(sb.toString());
本身加個字邊界匹配,sb出來之後更好理解app