How to escape variable in regular expression


stáhnout snippet
zobrazení: SyntaxHighlighter | GeSHi | Holý text
# using \Q in regex

$string = "Placido P. Octopus";
$regex  = "P.";

$string =~ s/\Q$regex/Polyp/;
# $string is now "Placido Polyp Octopus"


Tagy:
perl 7 řádků | 2008-08-26 06:03:46