优化MAC地址正则(issue#IB95X4@Gitee)

This commit is contained in:
Looly
2024-12-05 10:39:13 +08:00
parent ae1a18cd20
commit b8f681fef1
3 changed files with 20 additions and 2 deletions

View File

@@ -132,7 +132,8 @@ public interface RegexPool {
/**
* MAC地址正则
*/
String MAC_ADDRESS = "((?:[a-fA-F0-9]{1,2}[:-]){5}[a-fA-F0-9]{1,2})|0x(\\d{12}).+ETHER";
//String MAC_ADDRESS = "((?:[a-fA-F0-9]{1,2}[:-]){5}[a-fA-F0-9]{1,2})|0x(\\d{12}).+ETHER";
String MAC_ADDRESS = "((?:[a-fA-F0-9]{1,2}[:-]){5}[a-fA-F0-9]{1,2})|((?:[a-fA-F0-9]{1,4}[.]){2}[a-fA-F0-9]{1,4})|[a-fA-F0-9]{12}|0x(\\d{12}).+ETHER";
/**
* 16进制字符串
*/

View File

@@ -0,0 +1,16 @@
package cn.hutool.core.util;
import cn.hutool.core.lang.PatternPool;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class IssueIB95X4Test {
@Test
void isMacTest() {
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab1c.2d3e.f468"));
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab:1c:2d:3e:f4:68"));
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab-1c-2d-3e-f4-68"));
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab1c2d3ef468"));
}
}