in reply to Elegant way to escape a string in a regex
Problems:
It might be best to split out the replacement.
my $repl = '//div[@id="abc"]'; s/.../$repl/
The following would also work:
s{...}{ q{//div[@id="abc"]} }e
s{...}{ '//div[@id="abc"]' }e
Changed the delimiter to allow «\» to be used unescaped, and removed «\Q\E».
If you change the replacement expression's delimiter to «'», it will act as a single-quoted string literal instead of a double-quoted string literal.
s{...}'//div[@id="abc"]'
Probably best to avoid this one because it's pretty obscure.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Elegant way to escape a string in a regex
by bliako (Abbot) on Apr 14, 2025 at 19:22 UTC | |
by ikegami (Patriarch) on Apr 14, 2025 at 19:34 UTC |