in reply to matching a "regex" expression

If you need to match a string literal that contains regular expression metacharacters, you can make sure to get the escaping right using either quotemeta or the \Q ... \E delimiters, as described in Quote and Quote like Operators. A working example:

my $regex = quotemeta q{document.write(this.location.href.replace(/\?r +esultof.*$/i, ''));}; my $j =~ s/$regex/something else/;

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: matching a "regex" expression
by slugger415 (Monk) on Jun 13, 2012 at 22:16 UTC

    thank you (both) that's just what I was looking for.