in reply to Sanitizing strings as regexes

Look at \Q and \E in perlre.
$string = '(.asdf[0-9])$'; $foo = '(.asdf[0-9])$'; if ( $foo =~ m/$string/ ) { print "won't work\n"; } if ( $foo =~ m/\Q$string\E/ ) { print "will work\n"; }

Replies are listed 'Best First'.
Re^2: Sanitizing strings as regexes
by AnomalousMonk (Archbishop) on Oct 10, 2008 at 17:16 UTC