DSL: How to clear regex capture groups? #1399
-
Is there a way to clear regex capture groups after a match is performed so that strings like Proof of concept: echo a=testing | mlr put -q '
val = "Test something here";
search = "(something)"i;
pre_match = "\1";
match = val =~ search;
post_match = "\1";
print "Variable (Pre-Match): " . pre_match;
print "Variable (Post-Match): " . post_match;
' Output: Variable (Pre-Match): \1
Variable (Post-Match): something Ideally there would be a way to set After a lot of debugging, I found this behavior to be the reason why some text replacements were not working as expected. Interestingly even a negative (
The capture groups appear to even persist into function calls when a match is performed in an outer (calling) function, which makes it even harder to track down when it results in unexpected behavior. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
@johnkerl is this better suited for a feature request/bug report? I haven't been able to find anything in Miller's docs relating to clearing regex capture groups. |
Beta Was this translation helpful? Give feedback.
-
@archetyped we can make an issue, no problem I am up-to-ears with dayjob right now, sorry for the delay ...... |
Beta Was this translation helpful? Give feedback.
-
@archetyped I am very sorry for the excessive delay :( Clearing: you can do
Correction: this isn't what you want -- it doesn't recover the "pre" behavior. Negative matches: I don't see a bug here but I think I misunderstand your ask:
Persisting within function calls: yes, this is ugly on my part:
I implemented the #1057 also raises this issue. #283 is a much better proposed solution: it would put all the machinery as local variables, rather than global state, which is a much more elegant design. And TBH I wish I'd done
Things to do:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the additional details.
Yes, I meant to update this thread that I tried all manner of combinations in the REPL and found that comparing two absent variables resets the regex capture groups, which was put into a function to make it quick and easy to reset on-demand:
Performing a regex search against
As seen in the following operations, a negative regex search replaces literal
I think I just find it strange that a negative regex search ( |
Beta Was this translation helpful? Give feedback.
@archetyped I am very sorry for the excessive delay :(
Clearing: you can do
"x" =~ "y"
(this is non-intuitive and is just a workaround -- see below for more):Correction: this isn't what you want -- it doesn't recover the "pre" behavior.
Negative matches: I don't see a bug here but I think I misunderstand your ask: