场景一 使用Patter和Matcher(全匹配)
String pattern="[0-9]{6,9}";
Pattern p=Pattern.compile(pattern);
Matcher m=p.matcher(ret.replaceAll(" ",""));
String target="";
if(m.matches()){
target = "xxxx="+ret.replaceAll(" ","");
}else{
target = ret.replaceAll(" ","");
}
场景二 只使用Patter(全匹配)
String content = "sdfsdf234234dgdfgdffg";
String pattern = "[0-9]{1,}";
boolean isMatch = Pattern.matches(pattern, content);
总结
String pattern="[0-9]{1,9}";
Pattern p=Pattern.compile(pattern);
Matcher m=p.matcher("d114dfgdfg56");
System.out.println(Pattern.matches(pattern,"dx33"));
System.out.println(m.matches());
while (m.find()){
System.out.println(m.group());
}