import re


def escape_special_characters_for_regex(expression):
    """Escapes special characters used in a regex. For example if the regex contains '#'
    (from the skill C# for example), it needs to be escaped by a backslash to build a valid regex."""
    spec_char_escaper = re.compile(r"[^a-zA-Z0-9]", re.IGNORECASE)
    expression = re.sub(spec_char_escaper, r'\1', expression)
    return expression