从Matcher.groupCount()的javadoc中:
返回此匹配器模式中的捕获组数。
零组按照惯例表示整个模式。它不包括在此计数中。
如果您检查返回值,
m.find()则返回
true,然后
m.group()返回
mas,因此匹配器会找到匹配项。
如果您要尝试计算
sin中出现的次数
mybooks.get(i).getBody(),则可以这样进行:
String s="mas"; // this is for testing, comes from a List<String>int hit=0;Pattern p=Pattern.compile(s,Pattern.CASE_INSENSITIVE);Matcher m = p.matcher(mybooks.get(i).getBody());while (m.find()) { hit++;}


