Simple code:
use 5.014;
use warnings;
my $re = <DATA>;
chomp $re;
my $re2 = qr/$re/;
say $re2;
__END__
^\w$
result:
(?^u:^\w$) #added the (?^u:
Is any correct way to decompile $re2 getting back the original regex?
Motivation: the regex is an config value, so need:
But can't save the compiled regex for the later use, because in every compiling the regex got expanded with the (?^u:, so after several cycles i ended with like:
(?^u:(?^u:(?^u:(?^u:(?^u:^\w$)))))
therefore the question are:
While I would just keep the string copy around for data usage, and then compile a copy when I needed to use it, you can also use the regexp_pattern function from the core re
module to return the pattern used to create a compiled regex:
use re 'regexp_pattern';
print regexp_pattern qr/^\w$/;
prints
^\w$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With