I would like to validate a hostname using only regualr expression.
Host Names (or \'labels\' in DNS jargon) were traditionally defined by RFC 952 and RFC 1123 and m
^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?
I used the following testbed written in Python to verify that it works correctly:
tests = [
('01010', False),
('abc', True),
('A0c', True),
('A0c-', False),
('-A0c', False),
('A-0c', True),
('o123456701234567012345670123456701234567012345670123456701234567', False),
('o12345670123456701234567012345670123456701234567012345670123456', True),
('', True),
('a', True),
('0--0', True),
]
import re
regex = re.compile('^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?