The Hostname Regex

后端 未结 5 974
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 02:36

I\'m looking for the regex to validate hostnames. It must completely conform to the standard. Right now, I have

^[0-9a-z]([0-9a-z\\-]{0,61}[0-9a-z])?(\\

5条回答
  •  一生所求
    2020-12-09 02:58

    What about:

    ^(?=.{1,255})([0-9A-Za-z]|_{1}|\*{1}$)(?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|\b-){0,61}[0-9A-Za-z])?)*\.?$
    

    for matching only one '_' (for some SRV) at the beginning and only one * (in case of a label for a DNs wildcard)

提交回复
热议问题