1
2
3
4
5
6
7
8
9
10
11
12
|
// RegExp
/*** RegExp.escape
accepts a string; returns the string with regex metacharacters escaped.
the returned string can safely be used within a regex to match a literal
string. escaped characters are [, ], {, }, (, ), -, *, +, ?, ., \, ^, $,
|, #, [comma], and whitespace.
*/
RegExp.escape = function (str) {
return str.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&");
};
|