def IPChecker_re(istr): import re istr = istr.replace('.', '-') pattern = re.compile("(?:[0-255]-){3}[0-255]") if pattern.match(istr) is not None: return True return False