JAVA 正则表达式:使用group方法计算匹配到的字符串个数
//待处理的字符串 <B>email:</B>admin@gmail.com<BR><B>,<B>email:</B>admin@gmail.com<BR><B>,<B>email:</B>admin@gmail.com<BR><B>,<B>email:</B>admin@gmail.com<BR><B>
String body = sb.toString();Pattern pattern = Pattern.compile("(<B>email:</B>)(.*@.*)(<BR><B>)");
//
Matcher matcher = pattern.matcher(body);
String email = "";
int matcherNum = 0;
while (matcher.find()) {
email = matcher.group(2);
matcherNum++;
}
System.out.println("matche Count is "+matcherNum);