例如从字符串中找出号码
String msg = "小明的号码是187****4012和150****9835";
String phone = "";
//校验信息中是否存在手机号
if(StringUtils.isNotBlank(msg)) {
Pattern pattern = Pattern.compile("1(3|4|5|6|7|8|9)\\d{9}$*");//正则表达式
Matcher matcher = pattern.matcher(StringUtils.deleteWhitespace(msg));
//判断是否匹配到子串
while (matcher.find()){
//返回匹配到的子字符串
phone += matcher.group()+",";
}
System.out.println(phone.substring(0,phone.length()-1););
}
结果:187****4012,150****9835
博客介绍了利用正则表达式从字符串中找出号码的相关内容,聚焦于正则表达式在字符串处理中的应用,体现了其在信息技术领域对特定信息提取的作用。
3万+





