public static void main(String[] args) {
String index = "手机号信息:13333333333 15555555555 18888888888" +
"邮箱信息:12@qq.com s123@163.com sdjkaxh@pci.com.cn 400-100-3233" +
"电话号码: 021-1584654 0215412111 0214511111";
//爬取电话号码,邮箱以及手机号
String regex = "(0\\d{2,6}-?\\d{5,20})|(\\w{1,30}@[0-9a-zA-Z]{2,20}(\\.[0-9a-zA-Z]{2,20}){1,2})" +
"|(1[3-9]\\d{9})|(400-?\\d{3,9}-?\\d{3,9})";
//将爬取规则编译成匹配对象
Pattern pattern = Pattern.compile(regex);
//获取一个容器来存取匹配对象
Matcher matcher = pattern.matcher(index);
//开始匹配
while (matcher.find()){
String re = matcher.group();
System.out.println(re);
}
}
java实现爬取文本中的手机号、邮箱以及电话号码
最新推荐文章于 2024-04-30 17:28:01 发布