mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
优化MAC地址正则(issue#IB95X4@Gitee)
This commit is contained in:
parent
b361614003
commit
6f5de187df
@ -136,7 +136,7 @@ public class PatternPool {
|
||||
/**
|
||||
* UUID
|
||||
*/
|
||||
public final static Pattern UUID = Pattern.compile(RegexPool.UUID, Pattern.CASE_INSENSITIVE);
|
||||
public final static Pattern UUID = Pattern.compile(RegexPool.UUID);
|
||||
/**
|
||||
* 不带横线的UUID
|
||||
*/
|
||||
@ -144,7 +144,7 @@ public class PatternPool {
|
||||
/**
|
||||
* MAC地址正则
|
||||
*/
|
||||
public static final Pattern MAC_ADDRESS = Pattern.compile(RegexPool.MAC_ADDRESS, Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern MAC_ADDRESS = Pattern.compile(RegexPool.MAC_ADDRESS);
|
||||
/**
|
||||
* 16进制字符串
|
||||
*/
|
||||
|
@ -136,7 +136,7 @@ public interface RegexPool {
|
||||
/**
|
||||
* UUID
|
||||
*/
|
||||
String UUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
||||
String UUID = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$";
|
||||
/**
|
||||
* 不带横线的UUID
|
||||
*/
|
||||
@ -144,7 +144,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进制字符串
|
||||
*/
|
||||
|
@ -0,0 +1,14 @@
|
||||
package org.dromara.hutool.core.regex;
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user