在 java/android 中获取带有匹配器的字符串列表
get list of string with matcher in java/android
我有一个像
这样的字符串
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.
我必须检索所有 phone-数字、日期和时间。
我打算使用模式和匹配器。
我的密码是
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 and this 它应该打印所有 phone 数字。
但我只得到第一个 phone 号码。
任何人都可以提出解决方案...
如果您删除将使用第一个数字的“if (match...)”语句,它对我来说工作正常:
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());
while (matcher.find()) {
System.out.println(matcher.group());
}
输出:
matcher.groupCount() 0
+919999999990
+919999999991
+919999999992
+919999999991
我有一个像
这样的字符串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.
我必须检索所有 phone-数字、日期和时间。 我打算使用模式和匹配器。
我的密码是
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 and this 它应该打印所有 phone 数字。 但我只得到第一个 phone 号码。
任何人都可以提出解决方案...
如果您删除将使用第一个数字的“if (match...)”语句,它对我来说工作正常:
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());
while (matcher.find()) {
System.out.println(matcher.group());
}
输出:
matcher.groupCount() 0
+919999999990
+919999999991
+919999999992
+919999999991