正则表达式——Pattern和Matcher使用

案例:将字符串中的所有手机号提取出来

使用Matcher的find和group方法

String s="我的手机号是18988888888,我曾用过18987654321,还用过18812345678";
//匹配手机正则表达式
String regex=''1[13578]\\d{9}";
//创建Pattern
Pattern p=Pattern.compile(regex);
//创建Matcher m=p.matcher(s);
//找到匹配正确的内容
while(m.find()){
System.out.println(m.group());
}
发布了89 篇原创文章 · 获赞 0 · 访问量 1530

猜你喜欢

转载自blog.csdn.net/ShiZaolin/article/details/104320294