我正在尝试使用 Python 中的正则表达式匹配有效域名中的标签:
DOMAIN_LABEL_RE = """
\A(
(?<![\d\-]) # cannot start with digit or hyphen, looking behind
([a-zA-Z\d\-]*?)
([a-zA-Z]+)# need at least 1 letter
([a-zA-Z\d\-]*?)
(?!\-) # cannot end with a hyphen, looking ahead
)\Z
"""
我正在尝试使用肯定和否定断言来避免标签开头或末尾的连字符。
但字符串 "-asdf" 仍然匹配: e.match(DOMAIN_LABEL_RE, "-asdf", re.VERBOSE).group()
我不明白为什么它仍然匹配。
谢谢你的帮助。
M。