Home  >  Q&A  >  body text

java - 我解析一个txt文件,把所有行组合成一个string,然后怎么拿出里面所有的手机号码,求代码实现

我解析一个txt文件,把所有行组合成一个string,然后怎么拿出里面所有的手机号码,求代码实现。
mobileCheck的正则表达式要怎么写
Pattern p = Pattern.compile(mobileCheck);
Matcher m = p.matcher(mobile); 接下去要怎么写呢

迷茫迷茫2765 days ago489

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:19:14

    A very basic implementation, you can find the solution by searching online.

    // A mobile phone number verification regular expression found online (may not be the latest)
    String mobileCheck = "(0|86|17951)?(13[0-9]|15[012356789]|17[0678]| 18[0-9]|14[57])[0-9]{8}";

    // It can probably be implemented as follows, reading the file and concatenating it into a string is not given

    String mobileCheck = "(0|86|17951)?(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}";
    String txtContent = "QQ:456456;座机是:0532214;手机1:13678888888;邮箱是:abc123@abc.com;手机2:15056666666。";
    
    Pattern p=Pattern.compile(mobileCheck); 
    Matcher m=p.matcher(txtContent); 
    while(m.find()) { 
         System.out.println(m.group()); 
    } 

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:19:14

    New to learning programming? This is not difficult, just check it out

    reply
    0
  • PHPz

    PHPz2017-04-18 09:19:14

    Use regular expressions

    reply
    0
  • Cancelreply