java - 我解析一个txt文件,把所有行组合成一个string,然后怎么拿出里面所有的手机号码,求代码实现
迷茫
迷茫 2017-04-18 09:17:14
0
3
456

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
巴扎黑

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()); 
} 
黄舟

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

PHPzhong

Use regular expressions

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!