/************************************************** * * Extensions for the RegExp object * * @author Ilya Lebedev * @modified $Date: 2006-11-12 15:20:46 +0300 (Вск, 12 Ноя 2006) $ * @version $Rev: 101 $ * @license LGPL 2.1 or later **************************************************/ /** * Does escape of special regexp characters * * Modified version from Simon Willison * * @see http://simon.incutio.com/archive/2006/01/20/escape * @param {String, Array} text to escape * @return {String} escaped result * @scope public */ RegExp.escape = function(text /* :String, Array */) /* :String */ { if (!arguments.callee.sRE) { var specials = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '$', '^', '\\' ]; arguments.callee.sRE = new RegExp( '(\\' + specials.join('|\\') + ')', 'g' ); } return isString(text)?text.replace(arguments.callee.sRE, '\\$1') :(isArray(text)?text.map(RegExp.escape).join("|") :""); }