In python, I can abuse capture group names in a substitution to simplify the substitution code, like:
$ python -c 'import regex; print(regex.sub("^(?<a>.)|(?<c>.)$|(?<b>.)"
+, lambda m:m.lastgroup, "xxx"))'
abc
In perl, if there is a single variable equivalent to
lastgroup, I can't find it, the closest I see is
%+:
$ perl -E'say "xxx" =~ s/^(?<a>.)|(?<c>.)$|(?<b>.)/@{[keys %+]}/gr'
abc
which isn't awful, but is there a better way I'm missing?
A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |