我有点搞不清楚"团队"和"捕获"之间的区别.NET的正则表达式语言.考虑下面的C代码:
MatchCollection matches = Regex.Matches("{Q}", @"^\{([A-Z])\}$");
我希望这会导致对字母"Q"的单个捕获,但如果我打印返回的MatchCollection
的属性,我会看到:
matches.Count: 1
matches[0].Value: {Q}
matches[0].Captures.Count: 1
matches[0].Captures[0].Value: {Q}
matches[0].Groups.Count: 2
matches[0].Groups[0].Value: {Q}
matches[0].Groups[0].Captures.Count: 1
matches[0].Groups[0].Captures[0].Value: {Q}
matches[0].Groups[1].Value: Q
matches[0].Groups[1].Captures.Count: 1
matches[0].Groups[1].Captures[0].Value: Q
这里到底是怎么回事?我知道整场比赛也有一次抓捕,但是小组是怎么进来的呢?为什么matches[0].Captures
不包括字母"q"的捕获?