1/**************************************************
2 *
3 *  Extensions for the RegExp object
4 *
5 *  @author Ilya Lebedev <ilya@lebedev.net>
6 *  @modified $Date: 2006-11-12 15:20:46 +0300 (Вск, 12 Ноя 2006) $
7 *  @version $Rev: 101 $
8 *  @license LGPL 2.1 or later
9 **************************************************/
10/**
11 *  Does escape of special regexp characters
12 *
13 *  Modified version from Simon Willison
14 *
15 *  @see http://simon.incutio.com/archive/2006/01/20/escape
16 *  @param {String, Array} text to escape
17 *  @return {String} escaped result
18 *  @scope public
19 */
20RegExp.escape = function(text /* :String, Array */) /* :String */ {
21  if (!arguments.callee.sRE) {
22    var specials = [
23      '/', '.', '*', '+', '?', '|',
24      '(', ')', '[', ']', '{', '}', '$', '^', '\\'
25    ];
26    arguments.callee.sRE = new RegExp(
27      '(\\' + specials.join('|\\') + ')', 'g'
28    );
29  }
30  return isString(text)?text.replace(arguments.callee.sRE, '\\$1')
31                       :(isArray(text)?text.map(RegExp.escape).join("|")
32                                      :"");
33}
34