Precede all special characters with a backslash.
183597
def escape(str):
    """"""
    out = ''
    for char in str:
        if char in '\\ ':
            out += '\\'
        out += char
    return out
346958
public static String escape(String input)
    {
        if (input.isEmpty())
            return input;

        String res = input.replaceAll(":", "\\\\:");
        char last = res.charAt(res.length() - 1);
        return last == '\\' || last == '!' ? res + '!' : res;
    }
1247721
def escape_md_section(text, snob=False):
    """"""
    text = md_backslash_matcher.sub(r"\\\1", text)
    if snob:
        text = md_chars_matcher_all.sub(r"\\\1", text)
    text = md_dot_matcher.sub(r"\1\\\2", text)
    text = md_plus_matcher.sub(r"\1\\\2", text)
    text = md_dash_matcher.sub(r"\1\\\2", text)
    return text
976881
function(string) {
            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can simply slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe
            // sequences.    
            var m = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            };
            if(/["\\\x00-\x1f]/.test(string)) {
                return '"' + string.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                    var c = m[b];
                    if(c) {
                        return c;
                    }
                    c = b.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + string + '"';
        }
965572
def escape_regex_special_chars(api_path):
    
    def substitute(string, replacements):
        pattern, repl = replacements
        return re.sub(pattern, repl, string)

    return functools.reduce(substitute, REGEX_REPLACEMENTS, api_path)
935457
def shell_escape(s):
    
    """
    if isinstance(s, PosixPath):
        s = unicode_(s)
    elif isinstance(s, bytes):
        s = s.decode('utf-8')
    if not s or any(c not in safe_shell_chars for c in s):
        return '"%s"' % (s.replace('\\', '\\\\')
                          .replace('"', '\\"')
                          .replace('`', '\\`')
                          .replace('$', '\\$'))
    else:
        return s
862484
public static function preBackSlash($str, $unify = false)
    {
        return self::_slash($str, '\\', true, true, $unify);
    }
967984
public static String escapeAttributeName(String s) {
        s = cleanWS(s);
        s = replaceAll(s, BackSlashPtn, EscBackSlash);
        s = replaceAll(s, EqualPtn, EscEqual);
        return s;
    }
106700
public static char eatBackslash(String a, int[] n) {
    if (!a.startsWith("\\")) {
      n[0] = 0;
      return ((char) 0);
    }
    // Unicodes BS u XXXX
    if (a.startsWith("\\u")) {
      try {
        n[0] = 6;
        return ((char) Integer.parseInt(a.substring(2, 6), 16));
      } catch (Exception e) {
        n[0] = -1;
        return ((char) 0);
      }
    }
    // Unicodes BS uu XXXX
    if (a.startsWith("\\uu")) {
      try {
        n[0] = 7;
        return ((char) Integer.parseInt(a.substring(3, 7), 16));
      } catch (Exception e) {
        n[0] = -1;
        return ((char) 0);
      }
    }
    // Classical escape sequences
    if (a.startsWith("\\b")) {
      n[0] = 2;
      return ((char) 8);
    }
    if (a.startsWith("\\t")) {
      n[0] = 2;
      return ((char) 9);
    }
    if (a.startsWith("\\n")) {
      n[0] = 2;
      return ((char) 10);
    }
    if (a.startsWith("\\f")) {
      n[0] = 2;
      return ((char) 12);
    }
    if (a.startsWith("\\r")) {
      n[0] = 2;
      return ((char) 13);
    }
    if (a.startsWith("\\\\")) {
      n[0] = 2;
      return ('\\');
    }
    if (a.startsWith("\\\"")) {
      n[0] = 2;
      return ('"');
    }
    if (a.startsWith("\\'")) {
      n[0] = 2;
      return ('\'');
    }
    // Octal codes
    n[0] = 1;
    while (n[0] < a.length() && a.charAt(n[0]) >= '0' && a.charAt(n[0]) <= '8')
      n[0]++;
    if (n[0] == 1) {
      n[0] = 0;
      return ((char) 0);
    }
    try {
      return ((char) Integer.parseInt(a.substring(1, n[0]), 8));
    } catch (Exception e) {
    }
    n[0] = -1;
    return ((char) 0);
  }
804516
def insert_slash(string, every=2):
    """"""
    return os.path.join(string[i:i+every] for i in xrange(0, len(string), every))
205059
def _f90str(self, value):
        """"""
        # Replace Python quote escape sequence with Fortran
        result = repr(str(value)).replace("\\'", "''").replace('\\"', '""')

        # Un-escape the Python backslash escape sequence
        result = result.replace('\\\\', '\\')

        return result
1204311
def pre(self, inputstring, **kwargs):
        """"""
        out = self.apply_procs(self.preprocs, kwargs, str(inputstring))
        logger.log_tag("skips", self.skips)
        return out
409150
@Nonnull
    public static String escapeString(@Nonnull String s) {
        // We replace double quotes with a back slash followed
        // by a double quote. We replace backslashes with a double
        // backslash
        if (s.indexOf('\"') == -1 && s.indexOf('\\') == -1) {
            return s;
        }
        StringBuilder sb = new StringBuilder(s.length() + 20);
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '\\') {
                sb.append("\\\\");
            } else if (ch == '\"') {
                sb.append("\\\"");
            } else {
                sb.append(ch);
            }
        }
        return verifyNotNull(sb.toString());
    }
1160534
@Override
    protected String escapeCharacter(char ch, char previousChar) {
      if(ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r') {
          return "";
      }
      switch(ch) {
          case '&': return ESCAPED_AMP;
          case '<': return ESCAPED_LT;
          case '>': return ESCAPED_GT;
          case '"': return ESCAPED_QUOTE;
          case '\'': return  ESCAPED_APOS;
          case '\\': return  ESCAPED_BACKSLASH;
          case '@': return ESCAPED_AT;
          case '`': return ESCAPED_BACKTICK;
          case NBSP: return ESCAPED_NON_BREAKING_SPACE;
          case LINE_SEPARATOR: return ESCAPED_LINE_SEPARATOR;
          case PARAGRAPH_SEPARATOR: return ESCAPED_PARAGRAPH_SEPARATOR;
      }
      return null;
    }
198433
def _to_bstr(l):
    """"""

    if isinstance(l, str):
        l = l.encode('ascii', 'backslashreplace')
    elif not isinstance(l, bytes):
        l = str(l).encode('ascii', 'backslashreplace')
    return l
322427
def escape(arg):
    "" 
    slash = '\\'
    special = '"$'

    arg = arg.replace(slash, slash+slash)
    for c in special:
        arg = arg.replace(c, slash+c)

    # print("ESCAPE RESULT: %s" % arg)
    return '"' + arg + '"'
65916
def _stripslashes(s):
  ''''''
  r = re.sub(r"\\(n|r)", "\n", s)
  r = re.sub(r"\\", "", r)
  return r