這就是我想要的匹配:這個正則表達式可以改進嗎?
this_is.ok.com
this_is.another_valid.domain.com
這裏有一些字符串我不想匹配:
this_one.is_not_ok.com
not_ok.com
also.not_ok
任何部分即可以有下劃線,除了的最終或倒數第二部分。
我想出正則表達式:
^([a-zA-Z0-9-_]{0,63}?\.)*([a-zA-Z0-9-]{0,63}?\.){1}([a-zA-Z0-9-]{0,63}?){1}$
它似乎工作,但我覺得它可能會更好。
注意:請不要討論域名中的下劃線。只需評論正則表達式。
您正在使用哪種正則表達式實現? –
**你的意思是**最終和倒數第二部分**? – anubhava
somepart.anotherpart.penultimatepart.ultimatepart –