Reputation: 282885
Given
var re = new Regex(@"(?<name>\w+)(x)\1\2");
Console.WriteLine(re.IsMatch("yxxy"));
Prints True
, it appears unnamed capturing groups are numbered starting with 1
, and then named capturing groups are assigned numbers afterwords. Is this correct/intended behaviour?
Upvotes: 2
Views: 1791
Reputation: 5003
At least MSDN says so. http://msdn.microsoft.com/en-us/library/bs2twtah(VS.71).aspx. In the newer version of this article it is confirmed, but it's more difficult to find this info. Named matched subexpressions are numbered consecutively from left to right after matched subexpressions.
Upvotes: 3