in reply to How to do regex backreferences within $variable replacement text?
Use the evaluate switch:
use warnings; use strict; my $user_defined_string = "abcabcabc"; my $user_defined_search = '(a)';
my $user_defined_replace = '---$1---';
my $user_defined_replace = '"---".$1."---"'; print "before: $user_defined_string\n"; $user_defined_string =~ s/$user_defined_search/$user_defined_replace/e +e; print "after: $user_defined_string\n";
prints:
Update: Fix the $user_defined_replace stringbefore: abcabcabc after: ---a---bcabcabc
BTW: you are aware that your user can execute pretty much any code using this technique?. You may want to do some aggressive filtering on the expressions that are allowed, and that may be pretty tricky to do!
|
|---|