My test cases didn't consider a '-' at either end of each domainlabel.
This should do it: regex = re.compile(r'^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\.?)+$', re.IGNORECASE)
My test cases didn't consider a '-' at either end of each domainlabel.
This should do it: r'^(([a- z0-9]|[ a-z0-9] [a-z0-9- ]*[a-z0- 9])\.?) +$', re.IGNORECASE)
regex = re.compile(