Given your rules, this code seems to do what you want but it uses a string eval, the use of which should be treated with caution.
use strict; use warnings; my @phrases = ( q{Supply from pOwerGeNERator53 today.}, q{DATA5Bus_C3 routed via PoweRgeNerator71 to data17buS_a3}, q{The newPowerGenErATor6 will not change}, ); my %rules = ( q{(?i)\bpowergenerator(\d+)\b} => q{qq{PowerGenerator$1}}, q{(?i)\bdata(\d+)bus_([ABC])(\d+)\b} => q{qq{@{ [ qq{Data$1Bus_} . uc $2 . $3 ] }}}, ); foreach my $phrase ( @phrases ) { print qq{Original: $phrase\n}; my $newPhrase = $phrase; foreach my $rule ( keys %rules ) { $newPhrase =~ s{$rule}{ eval $rules{ $rule } }eg; } print qq{ Amended: $newPhrase\n\n}; }
The output.
Original: Supply from pOwerGeNERator53 today. Amended: Supply from PowerGenerator53 today. Original: DATA5Bus_C3 routed via PoweRgeNerator71 to data17buS_a3 Amended: Data5Bus_C3 routed via PowerGenerator71 to Data17Bus_A3 Original: The newPowerGenErATor6 will not change Amended: The newPowerGenErATor6 will not change
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^3: regex capture case
by johngg
in thread regex capture case
by rmflow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |