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
Regex auto-atomicity too aggressive about \w and \b #74686
System.Text.RegularExpressions.Regex.Matches not returning expected matches. It returns no matches at all.
Reproduction Steps
varstringToMatch="sydney bogota berlin tokyo nairobi denver rio";Console.WriteLine($"Input: {stringToMatch}");GetMatches(@"(\b(?!bogo|nai)\w*\b)\w+",stringToMatch);GetMatches(@"\w*\b\w+",stringToMatch);voidGetMatches(stringexpression,stringstringToMatch){varreg=newSystem.Text.RegularExpressions.Regex(expression);Console.WriteLine($"\nOutput:");foreach(varmatchinreg.Matches(stringToMatch)){Console.WriteLine(match);}}
Looks like the issue is that we're making the starting loop atomic, and we shouldn't be, as doing so visibly affects the behavior. The \b can be used to make the first loop atomic, but it's zero-width, so we also need to evaluate against what comes after it; we might be able to get away with only doing so when the first loop has a non-0 minimum iteration count, but it's likely also diminishing returns at that point.
changed the title [-]Update bumpalong optimization causes failure to match in some cases[/-][+]Regex auto-atomicity too aggressive about \w and \b[/+]on Aug 28, 2022
ghost added
in-prThere is an active PR which will close this issue when it is merged
Activity
[-]Regex returning invalid match[/-][+]Update bumpalong optimization causes failure to match in some cases[/+]stephentoub commentedon Aug 28, 2022
Looks like the issue is that we're making the starting loop atomic, and we shouldn't be, as doing so visibly affects the behavior. The \b can be used to make the first loop atomic, but it's zero-width, so we also need to evaluate against what comes after it; we might be able to get away with only doing so when the first loop has a non-0 minimum iteration count, but it's likely also diminishing returns at that point.
[-]Update bumpalong optimization causes failure to match in some cases[/-][+]Regex auto-atomicity too aggressive about \w and \b[/+]