def escape_special_characters(s):
    """Add a backslash before characters that have special meanings in
    regular expressions. Python does not handle backslashes in regular
    expressions or substitution text so they must be escaped before
    processing.""" 

    special_chars = r'\\'
    new_string = ''
    for c in s:
        if c in special_chars:
            new_string += '\\'
        new_string += c
    return new_string