哪位兄弟给个验证MAC地址的正则表达式

时间:2022-06-23 12:53:14
要验证MAC地址
比如:
00-0B-2F-02-37-C8
00-E0-4C-77-B1-B6

从网上找到一个
^(?:(?'1'[0-9a-fA-F]{2})(?:\:)(?'2'[0-9a-fA-F]{2})(?:\:)(?'3'[0-9a-fA-F]{2})(?:\:)(?'4'[0-9a-fA-F]{2})(?:\:)(?'5'[0-9a-fA-F]{2})(?:\:)(?'6'[0-9a-fA-F]{2}))$|^(?:(?'1'[0-9a-fA-F]{2})(?:\-)(?'2'[0-9a-fA-F]{2})(?:\-)(?'3'[0-9a-fA-F]{2})(?:\-)(?'4'[0-9a-fA-F]{2})(?:\-)(?'5'[0-9a-fA-F]{2})(?:\-)(?'6'[0-9a-fA-F]{2}))$
发现不起作用

先谢谢了

4 个解决方案

#1


Mac地址以空格,"-",":"分开

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$ 

#2


MAC地址 正则表达式 
^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$ 
Mac地址以空格,"-",":"分开

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$ 

中间没有任何符号

#3


引用 2 楼 octverve 的回复:
MAC地址 正则表达式  
^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$  
Mac地址以空格,"-",":"分开 

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$  

中间没有任何符号 

正解。

#4


引用 3 楼 zhoufoxcn 的回复:
引用 2 楼 octverve 的回复:
MAC地址 正则表达式 
^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$ 
Mac地址以空格,"-",":"分开

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$ 

中间没有任何符号

正解。

正解,实践证明的

#1


Mac地址以空格,"-",":"分开

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$ 

#2


MAC地址 正则表达式 
^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$ 
Mac地址以空格,"-",":"分开

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$ 

中间没有任何符号

#3


引用 2 楼 octverve 的回复:
MAC地址 正则表达式  
^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$  
Mac地址以空格,"-",":"分开 

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$  

中间没有任何符号 

正解。

#4


引用 3 楼 zhoufoxcn 的回复:
引用 2 楼 octverve 的回复:
MAC地址 正则表达式 
^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$ 
Mac地址以空格,"-",":"分开

^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$ 

中间没有任何符号

正解。

正解,实践证明的