def escape(string):
    """ Returns the string with control characters for Pattern syntax escaped.
        For example: "hello!" => "hello\\!".
    """
    for ch in ('{', '}', '[', ']', '(', ')', '_', '|', '!', '*', '+', '^'):
        string = string.replace(ch, '\\' + ch)
    return string
