我有下面这段代码:为什么我得到从我的正则表达式匹配这些结果?
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)
有何区别?
所以0组就像是无关紧要的我吗? –
是的。你只需要使用组'1'作为计数开始形式'1'。 '0'是整个比赛的默认值。 – Saif
在这种情况下,我会再加1个组? –