课堂练习二

public static void main(String[] args) {
//
// Pattern p=Pattern.compile("a*b");//获取到了正则表达式
// Matcher m=p.matcher("aaaaab");//返回一个匹配器Matcher
// boolean b = m.matches();//看是否匹配  匹配就返回true
// System.out.println(b);
//
System.out.println("aaaaab".matches("a*b"));
String s="我的手机号15135228404,曾经用过的13653623709";
String regex="1[3578]\\d{9}";//手机号码的正则
// Pattern p=Pattern.compile(regex);
// Matcher m=p.matcher(s);
// boolean b = m.matches();
// System.out.println(b);
//
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(s);
//boolean  b=m.find();//找find
//System.out.println(b);
//String s1=m.group();//获取group/
//System.out.println(s1);
while(m.find()){
System.out.println(m.group());

}


}

猜你喜欢

转载自blog.csdn.net/qq_39539367/article/details/78215962