java 正则表达式用法:
public static void main(String[] args) {
String a = "110 (样张)121";
Pattern pattern = Pattern.compile("(\\d+)");
Matcher matcher = pattern.matcher(a);
if(matcher.find()){
System.out.println(matcher.group());
}
}
在group之前,必须用find()方法,否则会报错,Exception in thread "main" java.lang.IllegalStateException: No match found异常。
而find()还可以用find(int i)来换。