Skip to content

Regex (?:(?'G')|){n}(?#n > 0) always capture only once in .NET10 #132964

Description

@longxya

Description

In .NET10, regex (?:(?'G')|){n}(?#n > 0) always capture only once.

Reproduction Steps

using System;
using System.Text.RegularExpressions;

var input = "1";
var pattern = @"\w(?:(?'G')|){3}";
{
	Console.WriteLine("--------------------interpreter---------------------");
	var mh = Regex.Match(input, pattern);
	foreach(Capture capture in mh.Groups["G"].Captures)
	{
		Console.WriteLine($"Index:{capture.Index}, Length:{capture.Length}");
	}
}
{
	Console.WriteLine("--------------------Compiled---------------------");
	var mh = new Regex(pattern, RegexOptions.Compiled).Match(input);
	foreach(Capture capture in mh.Groups["G"].Captures)
	{
		Console.WriteLine($"Index:{capture.Index}, Length:{capture.Length}");
	}
}

Expected behavior

--------------------interpreter---------------------
Index:1, Length:0
Index:1, Length:0
Index:1, Length:0
--------------------Compiled---------------------
Index:1, Length:0
Index:1, Length:0
Index:1, Length:0

Actual behavior

--------------------interpreter---------------------
Index:1, Length:0
--------------------Compiled---------------------
Index:1, Length:0

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions