方法一:
String str="fsdfdsf12315f15哈12的";
String regEx="[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
String num=m.replaceAll("").trim().toString();
if(num.length()==20)
{
System.out.println("true");
}
else
System.out.println("false");
方法二:
String str = "xxx第1111111111111111111";
String regex = "\\d*";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while (m.find()) {
if (!"".equals(m.group()))
{
System.out.println("true");
}else
System.out.println("false");
}
String str="fsdfdsf12315f15哈12的";
String regEx="[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
String num=m.replaceAll("").trim().toString();
if(num.length()==20)
{
System.out.println("true");
}
else
System.out.println("false");
方法二:
String str = "xxx第1111111111111111111";
String regex = "\\d*";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while (m.find()) {
if (!"".equals(m.group()))
{
System.out.println("true");
}else
System.out.println("false");
}