求助 java正则表达式将中文括号里的内容提取出来

2024-12-25 22:39:16
推荐回答(4个)
回答1:

String re="行政专员(袁文全)";
String rex="[()]+";
String[] str=re.split(rex);
System.out.print(str[1]);

还有一个不是正则表达式的
String re="行政专员(袁文全)";
String str=re.substring(re.lastIndexOf("("),re.lastIndexOf(")"));
String s=str.substring(1,str.length());
System.out.print(s);

回答2:

Pattern p = Pattern.compile("\\(([^\\)]+)");
Matcher matcher = p.matcher("行政专员(袁文全)");
if (matcher.find() && matcher.groupCount() >= 1){
System.out.println(matcher.group(1));
}

回答3:

Pattern p = Pattern.compile("\\(([^\\)]+)");Matcher matcher = p.matcher("行政专员(袁文全)");if (matcher.find() && matcher.groupCount() >= 1){System.out.println(matcher.group(1)); }

回答4:

System.out.println( str.replaceAll(".*\\(|\\).*", ""));