def regex_esc(s):
    escaped = []
    for c in s:
        if c.isalnum():
            escaped.append(c)
        elif (c == ' '):
            escaped.append('\\ ')
        elif (c == '\t'):
            escaped.append('\\t')
        elif (c == '\n'):
            escaped.append('\\n')
        elif (c == '\r'):
            escaped.append('\\r')
        elif (string.punctuation.find(c) >= 0):
            escaped.append(('\\%s' % c))
        else:
            escaped.append(('\\x%02x' % ord(c)))
    return ''.join(escaped)
def regex_esc(s):
    escaped = []
    for c in s:
        if c.isalnum():
            escaped.append(c)
        elif (c == ' '):
            escaped.append('\\ ')
        elif (c == '\t'):
            escaped.append('\\t')
        elif (c == '\n'):
            escaped.append('\\n')
        elif (c == '\r'):
            escaped.append('\\r')
        elif (string.punctuation.find(c) >= 0):
            escaped.append(('\\%s' % c))
        else:
            escaped.append(('\\x%02x' % ord(c)))
    return .join(escaped)