作用:
1.字符串的格式校验 String类中提供了一个方法boolean = str.matchs(”regex”);
2.字符串的拆分及替换 String类中的方法replace split
3.字符串的查找 Pattern类—->模式 Matcher—->匹配器
//找寻长度为6的任意数字
String str = new String("123456abc787546hghf344538rfgd");
//1.利用Pattern类创建一个对象 相当于正则表达式
Pattern p = Pattern.compile("\\d{6}");
//2.利用Pattern模式对象创建一个匹配器
Matcher m = p.matcher(str);
//3.找寻满足条件的字符串
while(m.find()){
System.out.println(m.group());
//输出 123456 787546 344538
}