import re

fqdns = [
    "ad6.example.com",
    "ad4.example.com",
    "ad.example.com",
    "www.example.com",
    "pipa",
]

pattern = re.compile(
    r"^((?![-])[-_A-Z\d]{1,63}(?<!-)[.])*(?!-)[-_A-Z\d]{1,63}(?<!-)[.]?$", re.IGNORECASE
)

for entry in fqdns:
    regex_pass = pattern.match(entry)
    print(regex_pass)
