正则表达式理解

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

相关文章
相关标签/搜索