package test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestZz {
public static void main(String[] args) {
String str = "中华人民共和国,简称(中国)。";
Matcher mat = Pattern.compile("(?<=\\()(\\S+)(?=\\))").matcher(str);
String str1 = null;
String str2 = null;
while (mat.find()) {
str2 = mat.group();
System.out.println(mat.group());
}
System.out.println(str);
str1 = str.replace(str2, "");
System.out.println("one:"+str1+"two:"+str2);
str2 = "("+str2+")";
str1 = str.replace(str2, "");
System.out.println("one:"+str1+"two:"+str2);
}
}
https://www.cnblogs.com/manliu/p/4004696.html
|