Skip to content

Regex NonBacktracking lazy loops with IgnoreCase, and repeaters aren't as lazy as they should be #63395

@stephentoub

Description

@stephentoub

Description

NonBacktracking seems to have an issue with repeaters processed under IgnoreCase and their impact on lazy loops.

Reproduction Steps

using System.Text.RegularExpressions;

string pattern = ".*?\\da{2}";
string input = "This1Aa should 2Aa match";

Console.WriteLine($"Interpreter    : {new Regex(pattern, RegexOptions.IgnoreCase).Match(input)}");
Console.WriteLine($"Compiled       : {new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled).Match(input)}");
Console.WriteLine($"NonBacktracking: {new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.NonBacktracking).Match(input)}");

Expected behavior

Interpreter    : This1Aa
Compiled       : This1Aa
NonBacktracking: This1Aa

Actual behavior

Interpreter    : This1Aa
Compiled       : This1Aa
NonBacktracking: This1Aa should 2Aa

cc: @olsaarik, @veanes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions