java 正则表达式

 

 

String s = "xyz[abc%def]hij_";
StringBuffer sb = new StringBuffer();
Pattern p = Pattern.compile("[\\[\\%\\_]", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher m = p.matcher(s);
while (m.find()) {
	m.appendReplacement(sb, "[" + m.group() + "]");
}
m.appendTail();
System.out.println(s);
System.out.println(sb);

你可能感兴趣的:(正则表达式)