【发布时间】:2015-08-22 19:14:53
【问题描述】:
我有以下代码:
String content = "title = 123";
Pattern p = Pattern.compile("(title)");
Matcher m = p.matcher(content);
int i = 1;
while (m.find()) {
System.out.println("groupCount() = " + m.groupCount());
System.out.println("i = " + i++ + " found: " + m.group(0));
System.out.println("i = " + i++ + " found: " + m.group(1));
}
输出为:
groupCount() = 1
i = 1 found: title
i = 2 found: title
谁能告诉我为什么我有 1 组计数,以及我是否在 group(0) 和 group(1) 中得到正确的值?
group(0) 和 group(1) 之间有什么区别吗?
【问题讨论】: