import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "afbdg23556dg3552";
// 定义一个正则
String reglx = "\\d";
Pattern p = Pattern.compile(reglx);
Matcher m = p.matcher(str);
int count = 0;
// 找到一次,计数器累加一次
while (m.find()) {
count++;
}
System.out.println(count);
}
} |