def is_valid_regex ( regex ) : if len ( regex ) == 0 : return False try : re . compile ( regex ) return True except sre_constants . error : return False
python how to check regex
Function for checking a valid regex .
def is_valid_regex(regex):
    """Function for checking a valid regex."""
    if len(regex) == 0:
        return False
    try:
        re.compile(regex)
        return True
    except sre_constants.error:
        return False