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
Investigate adding capture support for RegexOptions.NonBacktracking #61904
As currently implemented, captures with RegexOptions.NonBacktracking are ignored, e.g. if you have an expression like abc(\w*)def, that's treated no differently from abc\w*def, and trying to access the resulting Match.Groups to access the \w* result will not be fruitful. While more challenging to do with a DFA, other production-quality engines (Rust, RE2, etc.) do support this implicitly. We should strongly investigate doing so for .NET 7.
Might this be an opportunity to make RegexOptions.ExplicitCapture default for the non backtracking engine, before anyone has taken dependency on it? I think this would mean adding RegexOptions.ImplicitCapture.
I think that one can maintain capture nodes in the SymbolicRegexNode AST that record the name and associate input position during the third phase of the matcher that keep track of the start/end position during matching. Currently this information is simply ignored as all capture nodes are essentially eliminated during the translation from RegexNode to SymbolicRegexNode (there are some tricky cases though e.g. in potential deep nesting of concatenations where captures are eliminated/flattened currently for perf reasons).
This mostly affects the 3rd phase of the matcher (unless there are watchdogs in which case the initial phase should already keep track of these, e.g. for input m(arg)us that would have watchdog #6 but also capture 1). I believe this would not add much more states and should not incur a big overhead and would not affect derivative semantics in general, but is a tricky change in general (mainly due to various optimizations).
Activity
danmoseley commentedon Nov 23, 2021
Might this be an opportunity to make RegexOptions.ExplicitCapture default for the non backtracking engine, before anyone has taken dependency on it? I think this would mean adding RegexOptions.ImplicitCapture.
stephentoub commentedon Nov 23, 2021
That's the exact opposite of what I'm suggesting happen.
veanes commentedon Nov 23, 2021
I think that one can maintain capture nodes in the
SymbolicRegexNodeAST that record the name and associate input position during the third phase of the matcher that keep track of the start/end position during matching. Currently this information is simply ignored as all capture nodes are essentially eliminated during the translation fromRegexNodetoSymbolicRegexNode(there are some tricky cases though e.g. in potential deep nesting of concatenations where captures are eliminated/flattened currently for perf reasons).This mostly affects the 3rd phase of the matcher (unless there are watchdogs in which case the initial phase should already keep track of these, e.g. for input
m(arg)usthat would have watchdog #6 but also capture 1). I believe this would not add much more states and should not incur a big overhead and would not affect derivative semantics in general, but is a tricky change in general (mainly due to various optimizations).stephentoub commentedon Feb 25, 2022
This has been implemented.