import re


def escape_regex(regex):
    """
    Escape regex metachars so user does not have to backslash them on command line

    :param regex: The regular expression to backslash metachars in

    :return: Properly backslashed regular expression metachars in regex
    """

    # src: https://stackoverflow.com/questions/4202538/escape-regex-special-characters-in-a-python-string
    regex = re.escape(regex)  ## This works better but regex is ugly in -v output
    # regex = re.sub(r'([\.\\\+\*\?\[\^\]\$\(\)\{\}\!\<\>\|\:\-])', r'\\\1', regex)

    return regex