【发布时间】:2012-07-16 15:57:39
【问题描述】:
如何在 Java 中找到与正则表达式匹配的所有子字符串? (类似于.Net中的Regex.Matches)
【问题讨论】:
标签: java regex multiple-matches
如何在 Java 中找到与正则表达式匹配的所有子字符串? (类似于.Net中的Regex.Matches)
【问题讨论】:
标签: java regex multiple-matches
创建一个匹配器并使用find() 将其定位到下一个匹配项。
【讨论】:
这是一个代码示例:
int countMatches(Pattern pattern, String str) {
int matches = 0;
Matcher matcher = pattern.matcher(str);
while (matcher.find())
matches++;
return matches;
}
【讨论】: