Finally got a moment away from child minding :). Here's a non-eval technique:
use warnings; use strict; my $udStr = "abcabcabc"; my $udSearch = '(a)'; my $udRep = '---$1---'; print "before: $udStr\n"; my $before = $udStr; $udStr =~ s/$udSearch/$udRep/; my @starts = @-; my @ends = @+; for (1..$#starts) { my $replace = substr $before, $starts[$_], $ends[$_] - $starts[$_]; $udStr =~ s/\$$_(?=\D)/$replace/; } print "after: $udStr\n";
Prints:
before: abcabcabc after: ---a---bcabcabc
This still doesn't fix (?{...}) and (??{...}) in $user_defined_search, but those could be filtered.
In reply to Re: How to do regex backreferences within $variable replacement text?
by GrandFather
in thread How to do regex backreferences within $variable replacement text?
by ManFromNeptune
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |