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.