todo: currently '/' characters are blindly being replaced but this will not allow regex queries to be used
494584
protected static Object escape(Object val) {
        if (val instanceof String) {
            return ((String)val).replaceAll("/", PATH_SEP_TOKEN);
        } else {
            return val;
        }
    }
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)
1133996
function (uri) {
	var lastSlash = uri.lastIndexOf("/");
	var sub;
	if (lastSlash == -1) {
		sub = uri;
	} else {
		sub = uri.substr(lastSlash + 1);
	}
	sub = sub.toLowerCase();
	var parsed = parseModuleName(sub);
	var path = removeFiletype(parsed.modulePath || sub);
	var matches = path.match(/^[\w-\s\.]+/);
	return matches ? matches[0] : "";
}
1085578
def unescape(s, quote=False):
    
    s = s.replace('&lt;', '<')
    s = s.replace('&gt;', '>')
    if quote:
        s = s.replace('&quot;', '"')
    s = s.replace('&amp;', '&')
    return s
1034938
function (url) {
            var tmp = url.replace(/\burl\s*/gi, "");    // removing url word
            tmp = tmp.charAt(0) === "(" ? tmp.substring(1, tmp.length - 1) : tmp; // removing brackets
            tmp = tmp.charAt(0) === "\'" || tmp.charAt(0) === "\"" ? tmp.substring(1, tmp.length - 1) : tmp; // removing quotes
            return tmp;
        }
166928
function inspect (s) {
  return s
    .replace(/\\/g, '\\\\')
    .replace(/\n/g, '\\n')
    .replace(/\t/g, '\\t')
    .replace(/"/g, '\\"')
    .replace(/\r/g, '\\r')
}
137353
function unescapeHtml(s) {
            if (_toString.call(s) != "[object String]") return s;
            if (!s) return "";
            return s.replace(/(&lt;)|(&gt;)|(&amp;)|(&quot;)/gm, function (match) {
                switch (match) {
                    case "&lt;":
                        return "<";
                    case "&gt;":
                        return ">";
                    case "&amp;":
                        return "&";
                    case "&quot;":
                        return "\"";
                    default:
                        return match;
                }
            });
        }
1164777
static String unescape(String input)
    {
        if (input.isEmpty())
            return input;

        String res = input.replaceAll("\\\\:", ":");
        char last = res.charAt(res.length() - 1);
        return last == '!' ? res.substring(0, res.length() - 1) : res;
    }
1344216
function unescape(str) {

    return str.replace(constants.REGEX.unescape, (match, hex1, hex2, hex3, octal, special) => {

        let hex = hex1 !== undefined ? hex1 : hex2 !== undefined ? hex2 : hex3 !== undefined ? hex3 : undefined;

        if (hex !== undefined) {
            return String.fromCodePoint(parseInt(hex, 16));

        } else if (octal !== undefined) {
            return String.fromCodePoint(parseInt(octal, 8));

        } else {
            return constants.SPECIAL_CHARS[special];
        }

    });

}
396175
function (string) {
    return (
      string
        // Escape backslash escapes!
        .replace(/\\(\S)/g, '\\\\$1')

        // Escape headings
        .replace(/^(#{1,6} )/gm, '\\$1')

        // Escape hr
        .replace(/^([-*_] *){3,}$/gm, function (match, character) {
          return match.split(character).join('\\' + character)
        })

        // Escape ol bullet points
        .replace(/^(\W* {0,3})(\d+)\. /gm, '$1$2\\. ')

        // Escape ul bullet points
        .replace(/^([^\\\w]*)[*+-] /gm, function (match) {
          return match.replace(/([*+-])/g, '\\$1')
        })

        // Escape blockquote indents
        .replace(/^(\W* {0,3})> /gm, '$1\\> ')

        // Escape em/strong *
        .replace(/\*+(?![*\s\W]).+?\*+/g, function (match) {
          return match.replace(/\*/g, '\\*')
        })

        // Escape em/strong _
        .replace(/_+(?![_\s\W]).+?_+/g, function (match) {
          return match.replace(/_/g, '\\_')
        })

        // Escape code _
        .replace(/`+(?![`\s\W]).+?`+/g, function (match) {
          return match.replace(/`/g, '\\`')
        })

        // Escape link brackets
        .replace(/[\[\]]/g, '\\{{{toMarkdown}}}') // eslint-disable-line no-useless-escape
    )
  }
583285
private String replaceScriptEscapeAndNewLines(String str) {
        StringBuilder result = new StringBuilder(str.length());
        char c = '\0';
        char prevC = '\0';
        boolean atEscape = false;
        for (int i = 0; i < str.length(); i++) {
            prevC = c;
            c = str.charAt(i);
            // set atEscape flag
            if (c == '\\') {
                // deal with 2nd '\\' char
                if (atEscape) {
                    result.append(c);
                    atEscape = false;
                    // set c to '\0' so that prevC doesn't match '\\'
                    // the next time round
                    c = '\0';
                } else {
                    atEscape = true;
                }
            } else if (atEscape) {
                if (c == 'n') {
                    result.append("\n");
                } else {
                    result.append(c);
                }
            } else {
                result.append(c);
            }
            // unset atEscape flag if required
            if (prevC == '\\') {
                if (atEscape) {
                    atEscape = false;
                }
            }
        }
        return result.toString();
    }
411112
def convert_reserved_characters(string)
    string.gsub!(/&quot;/, '\"')
    string.gsub!(/&apos;/, '\'')
    string.gsub!(/&amp;/,  '\&')
    string.gsub!(/&lt;/,   '\<')
    string.gsub!(/&lt;/,   '\>')
    string
  end
112962
function QueryString(search) {
        "use strict";
    
        if (search.substr(0, 1) === '?') {
            search = search.substr(1);
        }
    
        search = search.split('&')
    
        if (search == "") return {};
    
        for (var i = 0; i < search.length; ++i) {
    
            var param = search[i].split('=', 2);
            if (param.length != 2) {
                continue;
            }
    
            this[param[0]] = decodeURIComponent(param[1].replace(/\+/g, " "));
    
        }
    
    }
179079
function encodeEntities(value) {
  return value.
    replace(/&/g, '&amp;').
    replace(NON_ALPHANUMERIC_REGEXP, function(value){
      return '&#' + value.charCodeAt(0) + ';';
    }).
    replace(/</g, '&lt;').
    replace(/>/g, '&gt;');
}
1237812
function unescape(key) {
  var unescapeRegex = /(=0|=2)/g;
  var unescaperLookup = {
    '=0': '=',
    '=2': ':'
  };
  var keySubstring = key[0] === '.' && key[1] === '$' ? key.substring(2) : key.substring(1);

  return ('' + keySubstring).replace(unescapeRegex, function (match) {
    return unescaperLookup[match];
  });
}
805637
function convertUrlPatternToRegex(pattern) {

    // pattern = pattern.replace(new RegExp('{[a-zA-Z0-9\\-_~]*}', 'gi'), '[a-zA-Z0-9\\-_~]+');

    // let's try a different way...
    // first, ui-router doesn't allow use of fwd slash in URL patterns because it's THE separator:

    // however. we /do/ sometimes want to be able to capture the rest of a huge url, at least on the server-side
    // case & point, old urls that point to /search/stuff/morestuff/otherstuff
    // so now we have to respect a trailing /search/{term:*}, which just grabs the whole damn tail

    var segments = pattern.split('/');
    var convertedSegments = [];
    for ( var i = 0, len = segments.length; i < len; i++ ) {
        var converted = convertUrlSegmentToRegex(segments[i]);
        convertedSegments.push(converted);
        if ( converted === urlPathPattern ) {
            // short-circuit out of this- we mean to capture the rest of the url with this...
            break;
        }
    }
    // more clever, but since we sometimes want to short-circuit, we use the loop instead
    /*
    var convertedSegments = segments.map(function (segment) {
        return convertUrlSegmentToRegex(segment); // so let's just convert each segment separately
    });
    */
    pattern = convertedSegments.join('/');

    pattern = pattern.replace(regexSlash, '\\/');
    pattern = '^' + pattern + '$';
    return new RegExp(pattern);
}
1152691
function getRegExpTags(opt, fileUrl) {
	function parseTag(tag, replacement) {
		return new RegExp(escapeStringRegexp(tag).replace(PATH_REGEX, replacement || FILE_PATH_REGEX), 'g');
	}

	if (fileUrl) {
		return {
			start: parseTag(opt.start, fileUrl),
			end: parseTag(opt.end, fileUrl)
		}
	}
	return {
		start: parseTag(opt.start),
		startex: parseTag(opt.start, "(.+)"),
		end: parseTag(opt.end)
	}
}