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.Match fails for the .* pattern when startat is non-zero #42390
.NET SDK (reflecting any global.json):
Version: 5.0.100-rc.1.20452.10
Commit: 473d1b592e
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\
Host (useful for support):
Version: 5.0.0-rc.1.20451.14
Commit: 38017c3
This is due to #1706. That PR adds an optimization that automatically adds a beginning-of-line anchor to a pattern that begins with .*. This lets the implementation skip backtracking by jumping to the start of the next line when it fails to match. This, however, didn't factor in the possibility that matching might be starting in the middle of a line, in which case when it goes to match, the BOL node itself may fail to match.
The simple fix is to just delete the optimization, i.e. remove this code:
That removes a valuable optimization, but I'm not sure if there's a good way to save it. One thought is to add a new kind of anchor, one that behaves like BOL for the purposes of jumping ahead in FindFirstChar but that doesn't actually require any matching in Go. I expect that would work, but it's probably too late to do so for .NET 5.
Activity
stephentoub commentedon Sep 17, 2020
@slozier, thanks for the very helpful repro.
This is due to #1706. That PR adds an optimization that automatically adds a beginning-of-line anchor to a pattern that begins with
.*. This lets the implementation skip backtracking by jumping to the start of the next line when it fails to match. This, however, didn't factor in the possibility that matching might be starting in the middle of a line, in which case when it goes to match, the BOL node itself may fail to match.The simple fix is to just delete the optimization, i.e. remove this code:
runtime/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs
Lines 353 to 403 in a747fee
That removes a valuable optimization, but I'm not sure if there's a good way to save it. One thought is to add a new kind of anchor, one that behaves like BOL for the purposes of jumping ahead in FindFirstChar but that doesn't actually require any matching in Go. I expect that would work, but it's probably too late to do so for .NET 5.
@pgovind, @danmosemsft, thoughts?
jeffhandley commentedon Sep 19, 2020
Fixed in #42408 (master) and #42409 (release/5.0)