【发布时间】:2015-06-23 20:23:47
【问题描述】:
我有一个类似
的字符串number +919999999990 time at:07:42:45 on 10.04.2014, number
+919999999991 time at:08:42:45 on 11.05.2014, number +919999999992 time at:075:42:45 on 05.03.2014 , number +9199999999913 ,time at:27:40:45 on 09.04.2015.
我必须检索所有电话号码、日期和时间。 我打算使用模式和匹配器。
我的代码是
String extra1="number +919999999990 time at:07:42:45 on 10.04.2014, number +919999999991 time at:08:42:45 on 11.05.2014, number +919999999992 time at:075:42:45 on 05.03.2014 , number +9199999999913 ,time at:27:40:45 on 09.04.2015.";
Pattern pattern = Pattern.compile("\\+\\d{12}");
Matcher matcher = pattern.matcher(extra1);
System.out.println("matcher.groupCount() "+matcher.groupCount());
if (matcher.find()) {
while(matcher.find()) {
System.out.println(matcher.group());
}
} else {
System.out.println("Not Found");
}
根据this 和this 它应该打印所有电话号码。 但我只得到第一个电话号码。
任何人都可以提出解决方案...
【问题讨论】:
-
在控制台应用程序中,打印除第一个数字之外的所有数字。 (它不会打印第一个数字,因为您在打印任何内容之前调用了两次
find...) -
@Jon Skeet 谢谢...
标签: java android string list matcher