regex - Perl search and replace with variable and capture group -
as question says, trying search replace using variable , capture group. is, replace string contains $1. followed answers here , here, did not working me; $1 comes through in replace. can me spot problem?
i reading regular expressions file so:
while( $line = <$file>) { @findrep = split(/:/, $line); $find = $findrep[0]; $replace = '"$findrep[2]"'; # contains $1 $alltxt =~ s/$find/$replace/ee; } if manually set my $replace = '"$1 stuff"' replace works expected. have played around every single/double quoting , /e combination can think of.
you're using single quotes $findrep[2] isn't interpolated. try instead:
my $replace = qq{"$findrep[2]"};
Comments
Post a Comment