Closed
Description
Regex regex = new("@(a*)+?");
MatchCollection mc = regex.Matches("@");
foreach (Match m in mc)
{
Console.WriteLine($"{m.Index} .. {m.Length + m.Index}");
Console.WriteLine(m.ToString());
}
On other regex engines, like PCRE, Nim, Python, Javascript, and Golang you would get 0 .. 1
On .NET Framework this displays 1 .. 1
On .NET 6 it gives
1 .. 3
Unhandled exception. System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
at System.String.Substring(Int32 startIndex, Int32 length)
at System.Text.RegularExpressions.Capture.get_Value()
at System.Text.RegularExpressions.Capture.ToString()
at Program.<Main>$(String[] args) in C:\Users\danmose\source\repos\ConsoleApp31\ConsoleApp31\Program.cs:line 191
@stephentoub first bug from running Nim tests.