Check for a valid domain name in a string?

后端 未结 5 976
悲哀的现实
悲哀的现实 2020-12-10 04:39

I am using python and would like a simple api or regex to check for a domain name\'s validity. By validity I am the syntactical validity and not whether the domain name actu

5条回答
  •  情深已故
    2020-12-10 05:34

    The answers are all pretty outdated with the spec at this point. I believe the below will match the current spec correctly:

    r'^(?=.{1,253}$)(?!.*\.\..*)(?!\..*)([a-zA-Z0-9-]{,63}\.){,127}[a-zA-Z0-9-]{1,63}$'
    

提交回复
热议问题