如何在Java中获得多个正则表达式匹配?

如何在Java中找到与正则表达式匹配的所有子字符串? (类似于.Net中的Regex.Matches )

创建一个匹配器并使用find()将其定位在下一个匹配项上。

这是一个代码示例:

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