in reply to Re: Regexp substitution using variables
in thread Regexp substitution using variables
It's working, and crucially supports back-references
That's interesting as I cannot get this to support back-references...this is very similar to my initial attempt. So I have attempted to replicate it:
This printsuse strict; my $pattern = '(testing)'; my $replacement = 'New \1'; my $flags = 'i'; my $value = 'My Testing Text'; $replacement =~ s/\\/\\\\/g; eval "\$value =~ s/$pattern/$replacement/$flags"; print "$value\n";
It doesn't substitute the capture.My New \1 Text
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regexp substitution using variables (updated)
by AnomalousMonk (Archbishop) on Nov 26, 2020 at 03:19 UTC |