Skip to content

Commit b8f681f

Browse files
committed
优化MAC地址正则(issue#IB95X4@Gitee)
1 parent ae1a18c commit b8f681f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# 🚀Changelog
33

44
-------------------------------------------------------------------------------------------------------------
5-
# 5.8.35(2024-12-04)
5+
# 5.8.35(2024-12-05)
66

77
### 🐣新特性
88
* 【poi 】 优化ExcelWriter中使用比较器writer的方法,只对第一条数据进行排序(pr#3807@Github)
99
* 【extra 】 优化Ftp.download,返回false抛出异常(issue#3805@Github)
10+
* 【core 】 优化MAC地址正则(issue#IB95X4@Gitee)
1011

1112
### 🐞Bug修复
1213
* 【crypto 】 修复JWTSignerUtil.createSigner中algorithmId未转换问题(issue#3806@Github)

hutool-core/src/main/java/cn/hutool/core/lang/RegexPool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public interface RegexPool {
132132
/**
133133
* MAC地址正则
134134
*/
135-
String MAC_ADDRESS = "((?:[a-fA-F0-9]{1,2}[:-]){5}[a-fA-F0-9]{1,2})|0x(\\d{12}).+ETHER";
135+
//String MAC_ADDRESS = "((?:[a-fA-F0-9]{1,2}[:-]){5}[a-fA-F0-9]{1,2})|0x(\\d{12}).+ETHER";
136+
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";
136137
/**
137138
* 16进制字符串
138139
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.hutool.core.util;
2+
3+
import cn.hutool.core.lang.PatternPool;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class IssueIB95X4Test {
8+
9+
@Test
10+
void isMacTest() {
11+
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab1c.2d3e.f468"));
12+
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab:1c:2d:3e:f4:68"));
13+
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab-1c-2d-3e-f4-68"));
14+
Assertions.assertTrue(ReUtil.isMatch(PatternPool.MAC_ADDRESS, "ab1c2d3ef468"));
15+
}
16+
}

0 commit comments

Comments
 (0)