注意1:
从网上考过来的\d编译器会自动转换成\\d,需要还原成\d
"([a-z]+)(\\\\d+)"
注意2
matcher.find() 需要遍历多次,matcher.group(i)) 0是匹配字符,1是分组开始
public void isNumber() {
Pattern pattern = Pattern.compile("([a-z]+)(\\d+)");
Matcher matcher = pattern.matcher("ads12121adf3334");
while (matcher.find()) {
for (int i = 0; i <= matcher.groupCount(); i++) {
Log.i("test11", "position:"+i+"---"+matcher.group(i));
}
Log.i("test11","---------");
}
}
07-16 17:09:48.018 16236-16236/? I/test11: position:0---ads12121
07-16 17:09:48.018 16236-16236/? I/test11: position:1---ads
07-16 17:09:48.018 16236-16236/? I/test11: position:2---12121
07-16 17:09:48.018 16236-16236/? I/test11: ---------
07-16 17:09:48.018 16236-16236/? I/test11: position:0---adf3334
07-16 17:09:48.018 16236-16236/? I/test11: position:1---adf
07-16 17:09:48.018 16236-16236/? I/test11: position:2---3334
07-16 17:09:48.018 16236-16236/? I/test11: ---------