给字符串s中的a,b,cd字符外层套上 标签 import java.util.regex.Matcher;import java.util.regex.Pattern;public class RegexTest {public static void main(String[] args) {//给字符串s中的a,b,cd字符外层套上 标签String s =
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static void main(String[] args) {
//给字符串s中的a,b,cd字符外层套上标签
String s = "a123bcdee";
String regex = "a|b|cd";
Pattern r = Pattern.compile(regex);
Matcher m = r.matcher(s);
StringBuffer sb = new StringBuffer();
while(m.find()){
m.appendReplacement(sb,""+m.group()+"");
}
System.out.println(sb.toString());
m.appendTail(sb);
System.out.println(sb.toString());
}
}