In Perl regular expressions, you can surround a subexpression with \\Q
and \\E
to indicate that you want that subexpression to be matched as a lite
Quotemeta isn't implemented natively as far as I know, but I've used this a few months ago for just this:
function quotemeta (str) {
// http://kevin.vanzonneveld.net
// + original by: Paulo Freitas
// * example 1: quotemeta(". + * ? ^ ( $ )");
// * returns 1: '\. \+ \* \? \^ \( \$ \)'
return (str + '').replace(/([\.\\\+\*\?\[\^\]\$\(\)])/g, '\\$1');
}
From http://phpjs.org/functions/quotemeta:496