Perl Programming/Keywords/quotemeta
Appearance
The quotemeta keyword
[edit | edit source]The quotemeta command returns the value of EXPRESSION such that all the ASCII non-"word" characters (that do not match with [A-Za-z_0-9]) are backslashed. This is the internal function implementing the \Q escape in double-quoted strings. If EXPRESSION is not passed, the function uses $_ instead.
Syntax
[edit | edit source] quotemeta EXPRESSION Examples
[edit | edit source]my $sentence = 'The quick brown fox jumpes over and over again.'; my $substring = 'quick.*?fox'; my $quoted_substring = quotemeta($substring); $sentence =~ s{$quoted_substring}{big bad wolf}; print '"', $sentence, "\"\n\"", $substring, "\"\n\"", $quoted_substring, "\"\n"; returns the following:
"The quick brown fox jumpes over and over again." "quick.*?fox" "quick\.\*\?fox"