You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Newline causes empty regex capture groups when NonBacktracking in dotnet 9 and above #120202
Found while upgrading 8 -> 10, but appears in 9 as well. I'm fairly sure I can't find an explanation of it in the documentation.
Both Nonbacktracking and having the final character be a \n rather than any other kind of whitespace appear to be critical to triggering the bug. Nonbacktracking is in there because this case was cut down from a much larger regular expression while trying to diagnose this. It is important to the larger expression for performance.
Reproduction Steps
`using System.Text.RegularExpressions;
string line = "A\n";
string expression = "^(A)(\s)";
Match match = Regex.Match(line, expression, RegexOptions.IgnoreCase | RegexOptions.NonBacktracking);
if (!match.Success)
{
System.Environment.Exit(1);
}
Activity
dotnet-policy-service commentedon Sep 29, 2025
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.
Fix issue number reference in test comment
Fix NonBacktracking regex empty capture groups with newline at end of…