Last active
July 2, 2023 10:40
-
-
Save neu5ron/66078f804f16f9bda828 to your computer and use it in GitHub Desktop.
Valid domain name regex including internationalized domain name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
domain_regex = r'(([\da-zA-Z])([_\w-]{,62})\.){,127}(([\da-zA-Z])[_\w-]{,61})?([\da-zA-Z]\.((xn\-\-[a-zA-Z\d]+)|([a-zA-Z\d]{2,})))' | |
#Python | |
domain_regex = '{0}$'.format(domain_regex) | |
valid_domain_name_regex = re.compile(domain_regex, re.IGNORECASE) | |
self.domain_name = self.domain_name.lower().strip().encode('ascii') | |
if re.match(valid_domain_name_regex, self.domain_name ): | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome