该方法
groupCount返回中的组数
Pattern。
中的组用
Pattern圆括号分隔。
您不
Pattern包含任何群组。
如果您要查找匹配数,请
while在
Matcher的
find()方法上使用循环(返回
boolean)。
例如:
int myMatches = 0;while (matcher.find()) { myMatches++;}编辑
Java 7+的命名组 也用 括号定界,尽管它们遵循的语法比未命名组略复杂。
有关详情,请参见此处。

该方法
groupCount返回中的组数
Pattern。
中的组用
Pattern圆括号分隔。
您不
Pattern包含任何群组。
如果您要查找匹配数,请
while在
Matcher的
find()方法上使用循环(返回
boolean)。
例如:
int myMatches = 0;while (matcher.find()) { myMatches++;}编辑
Java 7+的命名组 也用 括号定界,尽管它们遵循的语法比未命名组略复杂。
有关详情,请参见此处。