代码改变世界

IPV6正则表达式

2018-05-03 10:00  shadowsky88  阅读(1674)  评论(0编辑  收藏  举报

IPV6正则表达式:   ^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$

 

 

//mac地址验证 例:18-03-73-9B-4A-D5
^([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}$ 横杆连接
^([A-Fa-f0-9]{2}){5}[A-Fa-f0-9]{2}$ 无间隔
^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$ 英文冒号连接
^([A-Fa-f0-9]{2} ){5}[A-Fa-f0-9]{2}$ 空格连接

// 前后台使用的mac地址校验正则(^和$可以严格控制开头和结尾);允许ipV4mac和ipV6mac
例:18-03-73-9B-4A-D5或18-03-73-9B-4A-D5-00-0e
^([A-Fa-f0-9]{2}-){5,7}[A-Fa-f0-9]{2}$|^([A-Fa-f0-9]{2}){5,7}[A-Fa-f0-9]{2}$|^([A-Fa-f0-9]{2}:){5,7}[A-Fa-f0-9]{2}$|^([A-Fa-f0-9]{2} ){5,7}[A-Fa-f0-9]{2}$