-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to replace replacement (for recursive grammars data) #337
Comments
I have just had a look at this, and what you suggest is not something that can easily be done because the code works by creating its output in a different buffer. When the global option is set, the scan continues in the old (input) buffer. I think you could implement what you want externally fairly efficiently by having two buffers. Start with buffer 1 holding the input, call pcre2_match(), remember the offset where it matched, call pcre2_substitute() with your match_data block and PCRE2_SUBSTITUTE_MATCHED but NOT the global option, and buffer 2 as the output. Start the next call to pcre2_match() with buffer 2 as the input and the appropriate offset and buffer 1 as the output. And so on. |
This is a feature request to allow to replace replacement, ie. to restart replace after next character of the match instead of the next character after the match.
Currently, recursive regexes must be manually restarted to match inner matches which imply some unneeded CPU overhead, especially in non-compiled programming languages.
recursive regex usecase: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.38.2/src/DocBlock/TypeExpression.php#L171 (matching for phpdoc grammar)
recursive regex replace usecase: https://github.com/atk4/data/blob/6bd51b730d/src/Schema/TestCase.php#L176 (replacing of possibly nested SQL expressions)
I propose a new PCRE flag which will force the PCRE engine replace process to continue at +1 character instead of +N characters (where N is number of matched characters).
The text was updated successfully, but these errors were encountered: