-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support for PCRE2_SUBSTITUTE_EXTENDED #14
Comments
The main issue here is that PCRE.NET implemented string replacement before PCRE had this feature, and subsequently kept it. It doesn't use PCRE's substitution feature at all. The whole replacement feature would need to be rewritten for this, and it would probably be slower because of memory management issues that would be introduced by this approach. But PCRE.NET provides replacement with a callback, just like .NET regex does, so you can provide a lambda which does the case transformation. I mean something like this: PcreRegex.Replace("...", "...", m => m.Value.ToLower()); |
Yeah when you just want to convert the entire match to a case it is easy enough. The tricky part is with more complex replacement strings, like:
I guess one would have to write some kind of in-between parser to turn the replacement string into a custom On an unrelated note: It seems the Edit: For context, this is to support cases where the replacement string is not built in code, but provided from an outside source. So it's not trivial to just write a lambda func directly. |
It's not that tricky: PcreRegex.Replace("...", "...", m => $"{m["first"].Value.ToUpper()} and {m["second"].Value.ToUpper()} {m[3]}");
That's exactly what PCRE.NET does actually. If you really need this feature quickly, maybe you could use this code as a starting point to build something that matches your needs.
OK, that makes sense.
That's weird, it's supposed to work. I'll check that. Anyway, another reason I didn't implement this is that I didn't want to have two incompatible replacement pattern syntaxes. I'm not sure what would be best here, I need to think about it. |
Hi guys, hope your week started great. As someone who has been watching
Wishing you both a great day. |
Agreed. I only mirrored .NET's replacement pattern syntax but never intended to replicate PCRE2's one. If I'll do anything about this, I'll integrate PCRE2's feature directly. |
By the way thank you for maintaining this project all this time, Lucas! A huge number of people are indebted to you. :) |
I fixed this in v0.10.1. There was a bug when |
Something I've always missed in the built-in regex engine of .NET is the ability to do case transformations in the replacement string. PCRE2 supports this by supplying an extra option (docs, Ctrl+F for
PCRE2_SUBSTITUTE_EXTENDED
).It would be great if it was possible to supply this "substitute extended" option in some way in PCRE.NET.
The text was updated successfully, but these errors were encountered: