2009-08-12 45 views

回答

14

创建一个匹配器并使用find()将它放置在下一个匹配项上。

15

下面是一个代码示例:

int countMatches(Pattern pattern, String str) { 
    int matches = 0; 
    Matcher matcher = pattern.matcher(str); 
    while (matcher.find()) 
    matches++; 
    return matches; 
}