如何从一段文字中提取出电话号码?(座机和手机)
假如我有这样一段文字: "你问的电话号码我找到了,她的座机是053123456789,她刚买了部手机,号码是13456789012.那你好好跟她聊聊吧! "请问怎么提取出里面的两个号码?
------解决方案--------------------终结贴:
String str = "你问的电话号码我找到了,她的座机是053123456789,她刚买了部手机075512345678,号码是13456789012.那你好好跟她聊聊吧! ";
String regMobile = "(13\\d{9}) ";
String regPhone = "(0\\d{11}) ";
Pattern p1 = Pattern.compile(regMobile);
Pattern p2 = Pattern.compile(regPhone);
Matcher m1 = p1.matcher(str);
Matcher m2 = p2.matcher(str);
while (m1.find()) {
for (int i = 0; i < m1.groupCount(); i++)
System.out.println(m1.group(i + 1));
}
while (m2.find()) {
for (int i = 0; i < m2.groupCount(); i++)
System.out.println(m2.group(i + 1));
}
搂主给分,楼下不要回了