import re


def escapeWithWildcards(term):
    """
    Escapes special characters of the Lucene Query Syntax except wildcards.

    @param term: The term to be escaped.
    @return the term with all the special characters escaped.
    """
    # First escape everything except \
    term = re.sub(r'[\+\-\&\|\!\(\)\{\}\[\]\^\"\:]', r'\\\g<0>', term)
    # Then escape \
    return re.sub(r'\\([^\+\-\&\|\!\(\)\{\}\[\]\^\"\:\*\?\~])', r'\\\\\g<1>',
                  term)