java实现爬取文本中的手机号、邮箱以及电话号码

时间:2025-03-09 07:55:16
  public static void main(String[] args) {
        String index = "手机号信息:13333333333 15555555555 18888888888" +
                "邮箱信息:12@  s123@ sdjkaxh@ 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 = (regex);

        //获取一个容器来存取匹配对象
        Matcher matcher = (index);

        //开始匹配
        while (()){
            String re = ();
            (re);
        }

    }