java正则表达式取括号⾥⾯的内容public static String changeCompName(String compName){
String NewCompName="";
//cm1230NHL6X7K(2)
//String tests="cm1230NHL6X7K(2)";
//compName=tests;
boolean twice=false;
if(compName.indexOf("(")>=0) twice=true;
Pattern p=Patternpile("([a-z]+)(\\d+)");
Matcher m=p.matcher(compName);
while(m.find()) {
up();
}
if(twice){
Pattern p2=Patternpile("(?<=\\()[^\\)]+");
Matcher m2=p2.matcher(compName);正则匹配尖括号
while(m2.find()) {
NewCompName+="("+m2.group()+")";
}
}
//System.out.println(NewCompName); //cm1230(2)
return NewCompName; }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论