def esc_regex(string):
    """Escapes non-literal regex characters in a string."""
    return string.replace('[', '\\[')\
                 .replace(']', '\\]')\
                 .replace('\\', '\\\\')\
                 .replace('^', '\\^')\
                 .replace('$', '\\$')\
                 .replace('.', '\\.')\
                 .replace('|', '\\|')\
                 .replace('?', '\\?')\
                 .replace('*', '\\*')\
                 .replace('+', '\\+')\
                 .replace('(', '\\(')\
                 .replace(')', '\\)')