^(?![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}(?<!-)$')
for (s, expected) in tests:
is_match = regex.match(s) is not None
print is_match == expected
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…