regex - What is the perl equivalent of PHP's preg_quote function? -


i have string want match within perl regex pattern, characters in may need escaping. in php, function preg_quote. equivalent in perl?

if want match contents of variable literally, enclose in \q...\e quotes, or use quotemeta function. both of these work:

use feature 'say'; $metachars = "1+2"; $escaped_metachars = quotemeta $metachars;  local $_ = "1112, 1+2";  "\\q...\\e: ",   /(\q$metachars\e)/; "quotemeta: ",   /($escaped_metachars)/; "no escaping: ", /($metachars)/; 

output:

\q...\e: 1+2 quotemeta: 1+2 no escaping: 1112 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -