in reply to Regexp substitution using variables
It's working, and crucially supports back-references — unlike the $res =~ s/(?$flags:$pattern)/$replacement/ solution.$replacement =~ s/\\/\\\\/g; eval "\$res =~ s/$pattern/$replacement/$flags";
Of course, the use of eval gives me the heebie-jeebies; but I'm not going to lose too much sleep as we already need to trust the people who write the configuration files that will contain the values used in the eval.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regexp substitution using variables
by AnomalousMonk (Archbishop) on Nov 26, 2020 at 09:50 UTC | |
|
Re^2: Regexp substitution using variables
by choroba (Cardinal) on Nov 26, 2020 at 07:13 UTC | |
|
Re^2: Regexp substitution using variables
by hippo (Archbishop) on Nov 26, 2020 at 09:50 UTC | |
|
Re^2: Regexp substitution using variables
by Bod (Parson) on Nov 26, 2020 at 01:11 UTC | |
by AnomalousMonk (Archbishop) on Nov 26, 2020 at 03:19 UTC |