Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

quotemeta

Escapes all non-“word” characters with a preceding backslash.

Returns a version of the string where every non-word character ([^A-Za-z0-9_]) is preceded by \. Useful for interpolating literal strings into regular expressions. If all characters are already word characters, the input is returned unchanged with no allocation.

Synopsis

my $safe = quotemeta($string);
$string =~ /\Q$pattern\E/;     # \Q invokes quotemeta

See Also

m//, s///