Following up to Regular expression to match hostname or IP Address? and using Restrictions on valid host names as a reference, what is the most readable, concise way to matc
Process each DNS label individually by excluding invalid characters and ensuring nonzero length.
def isValidHostname(hostname): disallowed = re.compile("[^a-zA-Z\d\-]") return all(map(lambda x: len(x) and not disallowed.search(x), hostname.split(".")))