String regex="\\d"; String input="123abc4k"; Pattern p=Pattern.compile(regex); Matcher m=p.matcher(input); while(m.find()){ System.out.println(m.group());//输出字符串中的数字 }
类似这样写,主要在于正则表达式