我有点搞不清楚“团队”和“俘虏”到底有什么区别。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”的截图呢?