Helper to escape JavaScript string as well as regular expression
961856
private static String escapeString(String s, char quote,
                          String doublequoteEscape,
                          String singlequoteEscape,
                          String backslashEscape) {
    StringBuilder sb = new StringBuilder(s.length() + 2);
    sb.append(quote);
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      switch (c) {
        case '\n': sb.append("\\n"); break;
        case '\r': sb.append("\\r"); break;
        case '\t': sb.append("\\t"); break;
        case '\\': sb.append(backslashEscape); break;
        case '\"': sb.append(doublequoteEscape); break;
        case '\'': sb.append(singlequoteEscape); break;
        case '>':
          // Unicode-escape the '>' in '-->' and ']]>'
          if (i >= 2
              && ((s.charAt(i - 1) == '-' && s.charAt(i - 2) == '-')
                  || (s.charAt(i - 1) == ']' && s.charAt(i - 2) == ']'))) {
            sb.append("\\u003e");
          } else {
            sb.append(c);
          }
          break;
        case '<':
          // Unicode-escape the '<' in '</script' and '<!--'
          final String END_SCRIPT = "/script";
          final String START_COMMENT = "!--";

          if (s.regionMatches(true, i + 1, END_SCRIPT, 0,
                              END_SCRIPT.length())) {
            sb.append("\\u003c");
          } else if (s.regionMatches(false, i + 1, START_COMMENT, 0,
                                     START_COMMENT.length())) {
            sb.append("\\u003c");
          } else {
            sb.append(c);
          }
          break;
        default:
          // No charsetEncoder provided - pass straight Latin characters
          // through, and escape the rest.  Doing the explicit character
          // check is measurably faster than using the CharsetEncoder.
          if (c > 0x1f && c <= 0x7f) {
            sb.append(c);
          } else {
            // Other characters can be misinterpreted by some JS parsers,
            // or perhaps mangled by proxies along the way,
            // so we play it safe and Unicode escape them.
            appendHexJavaScriptRepresentation(sb, c);
          }
      }
    }
    sb.append(quote);
    return sb.toString();
  }
577846
function (str) {
                if (!str) {
                    return str;
                }
                return String(str).replace(/[\uff-\uffff]/g, function (c) {
                    return escape(c).replace('%', '\\');
                });
            }
246011
function escaper(str) {
    return str == null ? EMPTY : EMPTY + String(str).replace(escapeReg, escapeCallback);
}
1247661
function escapeFormat(t) {
  return (
    t
      // Inline single underscore.
      .replace(/([^_])_([^_])/g, '$1 $2')
      // Leading or trailing underscore.
      .replace(/([^_])_$/, '$1 ')
      .replace(/^_([^_])/, ' $1')
      // Double underscore and double dash.
      .replace(/__/g, '_')
      .replace(/--/g, '-')
  )
}
1169081
def _escapeCharacters(tag):
	""""""
	for i,c in enumerate(tag.contents):
		if type(c) != bs4.element.NavigableString:
			continue
		c.replace_with(_escapeCharSub(r'\\\1', c))
1272517
function getRegex(str) {
  var s = str.split('').map(function(v) {
    //escape special chars
    if (
        '*'  === v   ||
        '.'  === v   ||
        '+'  === v   ||
        '('  === v   ||
        ')'  === v   ||
        '\\' === v   ||
        '?'  === v   ||
        '\'' === v   ||
        '$'  === v   ||
        '^'  === v   ||
        '/'  === v   ||
        '['  === v   ||
        ']'  === v
      ) v = '\\' + v;

    return '(' + v + ')';
  });
  s = '^(.*?)' + s.join('(.*?)') + '(.*?)(.*)$';
  return new RegExp(s, 'i');
}
872565
def escape_html(text):
    
    text = text.replace('&', '&amp;')
    text = text.replace('<', '&lt;')
    text = text.replace('>', '&gt;')
    text = text.replace('"', '&quot;')
    return text
306328
def legacy_html_escape(s):
    """"""
    s = s.replace("&", "&amp;")
    s = s.replace(">", "&gt;")
    s = s.replace("<", "&lt;")
    s = s.replace('"', "&#34;")
    s = s.replace("'", "&#39;")
    return s
954267
function escape_code(defaultRenderer) {
  return function(tokens, idx, options, env, slf) {
    tokens[idx].content = tokens[idx].content
      .slice(2, -2)
      .replace(/\\`/g, '__BACK_TICK__');

    return defaultRenderer(tokens, idx, options, env, slf);
  };
}
149166
def escape_ampersand(string):
    
    if not string:
        return string
    start_with_match = r"(\#x(....);|lt;|gt;|amp;)"
    # The pattern below is match & that is not immediately followed by #
    string = re.sub(r"&(?!" + start_with_match + ")", '&amp;', string)
    return string
1171322
function regEscape(str) {
  // essentially stolen from https://github.com/component/escape-regexp with a modified replacer
  return String(str).replace(/([.*+?=^!:${}()|[\]\/\\])/g, function (match, paren, index, orig) {
    if (match === ':' && orig[index + 1] !== '/')
      return match;
    
    // if star, it's a wildcard if only enclosed by forward slashes (or at start or end of string)
    if (match === '*' && (index === 0 || orig[index - 1] === '/') && (index + 1 === orig.length || orig[index + 1] === '/'))
      return '.*';
    
    return '\\' + match;
  });
}
1131830
public static String escapeJsString(String string, String quote) {
    // This should be expanded to match all invalid characters (e.g. newlines) but for the moment
    // we'll trust we'll only get quotes.
    Pattern escapePattern = Pattern.compile("([^\\\\])" + quote);

    // Prepend a space so that the regex can match quotes at the beginning of the string
    Matcher m = escapePattern.matcher(" " + string);
    StringBuffer sb = new StringBuffer();

    while (m.find()) {
      // $1 -> inserts the character before the quote \\\\\" -> \\", apparently just \" isn't
      // treated literally.
      m.appendReplacement(sb, "$1\\\\" + quote);
    }

    m.appendTail(sb);

    // Remove the prepended space.
    return sb.substring(1);
  }
484692
function RouteRule_escape(str, escape) {
        if (!Type.isString(str)) {
            throw new error.HttpError(500, {str: str}, 'RouteRule.escape: str must be a string type');
        } else if(!Type.isArray(escape)) {
            throw new error.HttpError(500, {escape: escape}, 'RouteRule.escape: escape must be a array type');
        }
        escape.forEach(function (item) {
            str = str.replace(item.key, item.value);
        });
        return str;
    }
1294277
def _escape(self, text):
        """"""
        ret = EMPTYSTRING if text is None else str(text)
        if self.escape:
            return html_escape(ret)
        else:
            return ret
137836
def _escape_markdown_literals(string):
    
    literals = list("\\`*_{}[]()<>#+-.!:|")
    escape = lambda c: '\\' + c if c in literals else c
    return "".join(map(escape, string))
809876
function escapeShellArg(value) {
    if (is.number(value)) {
        return value;
    }

    value = String(value);
    value = value.replace(/"/g, '\\"');

    return '"' + value + '"';
}
1041140
def escape(self, varname, value):
        
        f = self.escape_funcs.get(varname)
        return f(value) if f else value