in reply to How to do regex backreferences within $variable replacement text?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to do regex backreferences within $variable replacement text?
by Hue-Bond (Priest) on Sep 18, 2005 at 01:26 UTC | |
by GrandFather (Saint) on Sep 18, 2005 at 01:33 UTC | |
|
Re^2: How to do regex backreferences within $variable replacement text?
by Hue-Bond (Priest) on Sep 18, 2005 at 02:20 UTC | |
by Skeeve (Parson) on Sep 18, 2005 at 07:32 UTC |