在大写字母之前加入空格
str.replaceAll("(.)([A-Z])","$1 $2")
点号代表任意单个字符,$1和$2分别代表第一个group和第二个group。stackoverflow
去掉结尾的数字
str.replaceAll("\\d+$", "")stackoverflow
Java 使用string.match这个函数的正确方式
Pattern p=Pattern.compile("\\d+$");
Matcher m=p.matcher(localname);
while(m.find()){
System.out.println(m.group());//abc
}
或者直接写成
Pattern.compile("\\d+$").matcher(localname).find()
详细介绍见CSDN