code: def is_valid_regex(regex):
      
      if len(regex) == 0:
          return False
      try:
          re.compile(regex)
          return True
      except sre_constants.error:
          return False
docs: Function for checking a valid regex.