IPv4地址的正则表达式:

^((25[0-5]|2[0-4]\d|[01]?\d?\d)(.(25[0-5]|2[0-4]\d|[01]?\d?\d)){3})$

IPv6地址的正则表达式:

^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}:([0-9a-fA-F]{1,4}:){1,2}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,4}:([0-9a-fA-F]{1,4}:){1,3}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,3}:([0-9a-fA-F]{1,4}:){1,4}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,2}:([0-9a-fA-F]{1,4}:){1,5}[0-9a-fA-F]{1,4}|[0-9a-fA-F]{1,4}:([0-9a-fA-F]{1,4}:){1,6}[0-9a-fA-F]{1,4}|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,5}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$


原文地址: http://www.cveoy.top/t/topic/0qW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录