中文
public static void chineseStr(){
StringBuilder sb = new StringBuilder();
String s = "";
String pattern = "[\\u4e00-\\u9fa5]+";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
while (m.find()) {
sb.append(m.group());
}
System.out.println(sb.toString());
}
单引号
public static void singleStr(){
StringBuilder sb = new StringBuilder();
String s = "fed'dsd'";
String pattern = "\\'(.*?)\\'+";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
while (m.find()) {
sb.append(m.group());
}
System.out.println(sb.toString());
}
双引号里的内容
public static void doubleStr(){
StringBuilder sb = new StringBuilder();
String s = "fe\"d\"dfrtt\"tttg\"sd'";
String pattern = "\"(.*?)\"+";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
while (m.find()) {
sb.append(m.group());
}
System.out.println(sb.toString());
}
大括号里的内容
public static void bracketsStr(){
StringBuilder sb = new StringBuilder();
String s = "dfdfd规范化{风格}化";
String pattern = "\\{(.*?)\\}";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
while (m.find()) {
sb.append(m.group());
}
System.out.println(sb.toString());
}