in reply to Re^3: Precompiling substitution regex
in thread Precompiling substitution regex
Okay my stab at using captured groups as well is to use eval in the replacement evaluation, i.e.,
foreach (@SUB_REC) { $yourText =~ s/$_->[0]/eval qq{"$_->[1]")/eg; }
The above allows me to pass replacement strings and capture groups, e.g.,
my @SUB_REC = map {[qr{$_->[0]}, $_->[1]]} ( ['robert|bobby', 'bob'], ['(abc)(1234)(def)', '$1$3'] );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Precompiling substitution regex
by AnomalousMonk (Archbishop) on Jul 02, 2014 at 21:50 UTC |