RegExp.escape = function(text) {
if (!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\'
];
arguments.callee.sRE = new RegExp(
'(\' + specials.join('|\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\$1');
}
Regular Expressions simple strings search/replace escape method (with RE speed enhancment – precompilation)
Category: Uncategorized |
Tags: escape, expressions, match, pattern, precompile, regular, replace, speed, text
Leave a Reply
You must be logged in to post a comment.