mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
add RegexPool
This commit is contained in:
parent
28b9dd1a4e
commit
fbd67b0d17
@ -16,6 +16,7 @@
|
||||
* 【json 】 增加JSONWriter
|
||||
* 【core 】 IdUtil增加getWorkerId和getDataCenterId(issueI3Y5NI@Gitee)
|
||||
* 【core 】 JWTValidator增加leeway重载
|
||||
* 【core 】 增加RegexPool(issue#I3W9ZF@gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【json 】 修复XML转义字符的问题(issue#I3XH09@Gitee)
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@ -14,49 +12,49 @@ public class PatternPool {
|
||||
/**
|
||||
* 英文字母 、数字和下划线
|
||||
*/
|
||||
public final static Pattern GENERAL = Pattern.compile("^\\w+$");
|
||||
public final static Pattern GENERAL = Pattern.compile(RegexPool.GENERAL);
|
||||
/**
|
||||
* 数字
|
||||
*/
|
||||
public final static Pattern NUMBERS = Pattern.compile("\\d+");
|
||||
public final static Pattern NUMBERS = Pattern.compile(RegexPool.NUMBERS);
|
||||
/**
|
||||
* 字母
|
||||
*/
|
||||
public final static Pattern WORD = Pattern.compile("[a-zA-Z]+");
|
||||
public final static Pattern WORD = Pattern.compile(RegexPool.WORD);
|
||||
/**
|
||||
* 单个中文汉字
|
||||
*/
|
||||
public final static Pattern CHINESE = Pattern.compile(ReUtil.RE_CHINESE);
|
||||
public final static Pattern CHINESE = Pattern.compile(RegexPool.CHINESE);
|
||||
/**
|
||||
* 中文汉字
|
||||
*/
|
||||
public final static Pattern CHINESES = Pattern.compile(ReUtil.RE_CHINESES);
|
||||
public final static Pattern CHINESES = Pattern.compile(RegexPool.CHINESES);
|
||||
/**
|
||||
* 分组
|
||||
*/
|
||||
public final static Pattern GROUP_VAR = Pattern.compile("\\$(\\d+)");
|
||||
public final static Pattern GROUP_VAR = Pattern.compile(RegexPool.GROUP_VAR);
|
||||
/**
|
||||
* IP v4
|
||||
*/
|
||||
public final static Pattern IPV4 = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
|
||||
public final static Pattern IPV4 = Pattern.compile(RegexPool.IPV4);
|
||||
/**
|
||||
* IP v6
|
||||
*/
|
||||
public final static Pattern IPV6 = Pattern.compile("(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))");
|
||||
public final static Pattern IPV6 = Pattern.compile(RegexPool.IPV6);
|
||||
/**
|
||||
* 货币
|
||||
*/
|
||||
public final static Pattern MONEY = Pattern.compile("^(\\d+(?:\\.\\d+)?)$");
|
||||
public final static Pattern MONEY = Pattern.compile(RegexPool.MONEY);
|
||||
/**
|
||||
* 邮件,符合RFC 5322规范,正则来自:http://emailregex.com/
|
||||
* What is the maximum length of a valid email address? https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754
|
||||
* 注意email 要宽松一点。比如 jetz.chong@hutool.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱
|
||||
*/
|
||||
public final static Pattern EMAIL = Pattern.compile("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])", Pattern.CASE_INSENSITIVE);
|
||||
public final static Pattern EMAIL = Pattern.compile(RegexPool.EMAIL, Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 移动电话
|
||||
*/
|
||||
public final static Pattern MOBILE = Pattern.compile("(?:0|86|\\+86)?1[3-9]\\d{9}");
|
||||
public final static Pattern MOBILE = Pattern.compile(RegexPool.MOBILE);
|
||||
/**
|
||||
* 中国香港移动电话
|
||||
* eg: 中国香港: +852 5100 4810, 三位区域码+10位数字, 中国香港手机号码8位数
|
||||
@ -66,69 +64,69 @@ public class PatternPool {
|
||||
* 中国澳门 +853 Macao
|
||||
* 中国台湾 +886 Taiwan
|
||||
*/
|
||||
public final static Pattern MOBILE_HK = Pattern.compile("(?:0|852|\\+852)?\\d{8}");
|
||||
public final static Pattern MOBILE_HK = Pattern.compile(RegexPool.MOBILE_HK);
|
||||
/**
|
||||
* 中国台湾移动电话
|
||||
* eg: 中国台湾: +886 09 60 000000, 三位区域码+号码以数字09开头 + 8位数字, 中国台湾手机号码10位数
|
||||
* 中国台湾 +886 Taiwan 国际域名缩写:TW
|
||||
*/
|
||||
public final static Pattern MOBILE_TW = Pattern.compile("(?:0|886|\\+886)?(?:|-)09\\d{8}");
|
||||
public final static Pattern MOBILE_TW = Pattern.compile(RegexPool.MOBILE_TW);
|
||||
/**
|
||||
* 中国澳门移动电话
|
||||
* eg: 中国台湾: +853 68 00000, 三位区域码 +号码以数字6开头 + 7位数字, 中国台湾手机号码8位数
|
||||
* 中国澳门 +853 Macao 国际域名缩写:MO
|
||||
*/
|
||||
public final static Pattern MOBILE_MO = Pattern.compile("(?:0|853|\\+853)?(?:|-)6\\d{7}");
|
||||
public final static Pattern MOBILE_MO = Pattern.compile(RegexPool.MOBILE_MO);
|
||||
/**
|
||||
* 座机号码
|
||||
*/
|
||||
public final static Pattern TEL = Pattern.compile("0\\d{2,3}-[1-9]\\d{6,7}");
|
||||
public final static Pattern TEL = Pattern.compile(RegexPool.TEL);
|
||||
/**
|
||||
* 座机号码+400+800电话
|
||||
*
|
||||
* @see <a href="https://baike.baidu.com/item/800">800</a>
|
||||
*/
|
||||
public final static Pattern TEL_400_800 = Pattern.compile("0\\d{2,3}[\\- ]?[1-9]\\d{6,7}|[48]00[\\- ]?[1-9]\\d{6}");
|
||||
public final static Pattern TEL_400_800 = Pattern.compile(RegexPool.TEL_400_800);
|
||||
/**
|
||||
* 18位身份证号码
|
||||
*/
|
||||
public final static Pattern CITIZEN_ID = Pattern.compile("[1-9]\\d{5}[1-2]\\d{3}((0\\d)|(1[0-2]))(([012]\\d)|3[0-1])\\d{3}(\\d|X|x)");
|
||||
public final static Pattern CITIZEN_ID = Pattern.compile(RegexPool.CITIZEN_ID);
|
||||
/**
|
||||
* 邮编,兼容港澳台
|
||||
*/
|
||||
public final static Pattern ZIP_CODE = Pattern.compile("^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[0-7]|6[0-7]|7[0-5]|8[0-9]|9[0-8])\\d{4}|99907[78]$");
|
||||
public final static Pattern ZIP_CODE = Pattern.compile(RegexPool.ZIP_CODE);
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
public final static Pattern BIRTHDAY = Pattern.compile("^(\\d{2,4})([/\\-.年]?)(\\d{1,2})([/\\-.月]?)(\\d{1,2})日?$");
|
||||
public final static Pattern BIRTHDAY = Pattern.compile(RegexPool.BIRTHDAY);
|
||||
/**
|
||||
* URL
|
||||
*/
|
||||
public final static Pattern URL = Pattern.compile("[a-zA-z]+://[^\\s]*");
|
||||
public final static Pattern URL = Pattern.compile(RegexPool.URL);
|
||||
/**
|
||||
* Http URL
|
||||
*/
|
||||
public final static Pattern URL_HTTP = Pattern.compile("(https://|http://)?([\\w-]+\\.)+[\\w-]+(:\\d+)*(/[\\w- ./?%&=]*)?");
|
||||
public final static Pattern URL_HTTP = Pattern.compile(RegexPool.URL_HTTP, Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 中文字、英文字母、数字和下划线
|
||||
*/
|
||||
public final static Pattern GENERAL_WITH_CHINESE = Pattern.compile("^[\u4E00-\u9FFF\\w]+$");
|
||||
public final static Pattern GENERAL_WITH_CHINESE = Pattern.compile(RegexPool.GENERAL_WITH_CHINESE);
|
||||
/**
|
||||
* UUID
|
||||
*/
|
||||
public final static Pattern UUID = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", Pattern.CASE_INSENSITIVE);
|
||||
public final static Pattern UUID = Pattern.compile(RegexPool.UUID, Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 不带横线的UUID
|
||||
*/
|
||||
public final static Pattern UUID_SIMPLE = Pattern.compile("^[0-9a-f]{32}$", Pattern.CASE_INSENSITIVE);
|
||||
public final static Pattern UUID_SIMPLE = Pattern.compile(RegexPool.UUID_SIMPLE);
|
||||
/**
|
||||
* MAC地址正则
|
||||
*/
|
||||
public static final Pattern MAC_ADDRESS = Pattern.compile("((?:[A-F0-9]{1,2}[:-]){5}[A-F0-9]{1,2})|0x(\\d{12}).+ETHER", Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern MAC_ADDRESS = Pattern.compile(RegexPool.MAC_ADDRESS, Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 16进制字符串
|
||||
*/
|
||||
public static final Pattern HEX = Pattern.compile("^[a-f0-9]+$", Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern HEX = Pattern.compile(RegexPool.HEX);
|
||||
/**
|
||||
* 时间正则
|
||||
*/
|
||||
@ -136,12 +134,7 @@ public class PatternPool {
|
||||
/**
|
||||
* 中国车牌号码(兼容新能源车牌)
|
||||
*/
|
||||
public final static Pattern PLATE_NUMBER = Pattern.compile(
|
||||
//https://gitee.com/loolly/hutool/issues/I1B77H?from=project-issue
|
||||
"^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[ABCDEFGHJK])|([ABCDEFGHJK]([A-HJ-NP-Z0-9])[0-9]{4})))|" +
|
||||
//https://gitee.com/loolly/hutool/issues/I1BJHE?from=project-issue
|
||||
"([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]\\d{3}\\d{1,3}[领])|" +
|
||||
"([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$");
|
||||
public final static Pattern PLATE_NUMBER = Pattern.compile(RegexPool.PLATE_NUMBER);
|
||||
|
||||
/**
|
||||
* 社会统一信用代码
|
||||
@ -153,7 +146,7 @@ public class PatternPool {
|
||||
* 第五部分:校验码1位 (数字或大写英文字母)
|
||||
* </pre>
|
||||
*/
|
||||
public static final Pattern CREDIT_CODE = Pattern.compile("^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$");
|
||||
public static final Pattern CREDIT_CODE = Pattern.compile(RegexPool.CREDIT_CODE);
|
||||
/**
|
||||
* 车架号
|
||||
* 别名:车辆识别代号 车辆识别码
|
||||
@ -162,14 +155,14 @@ public class PatternPool {
|
||||
* 十七位码、车架号
|
||||
* 车辆的唯一标示
|
||||
*/
|
||||
public static final Pattern CAR_VIN = Pattern.compile("^[A-Za-z0-9]{17}$");
|
||||
public static final Pattern CAR_VIN = Pattern.compile(RegexPool.CAR_VIN);
|
||||
/**
|
||||
* 驾驶证 别名:驾驶证档案编号、行驶证编号
|
||||
* eg:430101758218
|
||||
* 12位数字字符串
|
||||
* 仅限:中国驾驶证档案编号
|
||||
*/
|
||||
public static final Pattern CAR_DRIVING_LICENCE = Pattern.compile("^[0-9]{12}$");
|
||||
public static final Pattern CAR_DRIVING_LICENCE = Pattern.compile(RegexPool.CAR_DRIVING_LICENCE);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
|
169
hutool-core/src/main/java/cn/hutool/core/lang/RegexPool.java
Executable file
169
hutool-core/src/main/java/cn/hutool/core/lang/RegexPool.java
Executable file
@ -0,0 +1,169 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
/**
|
||||
* 常用正则表达式字符串池
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.7.3
|
||||
*/
|
||||
public interface RegexPool {
|
||||
/**
|
||||
* 英文字母 、数字和下划线
|
||||
*/
|
||||
String GENERAL = "^\\w+$";
|
||||
/**
|
||||
* 数字
|
||||
*/
|
||||
String NUMBERS = "\\d+";
|
||||
/**
|
||||
* 字母
|
||||
*/
|
||||
String WORD = "[a-zA-Z]+";
|
||||
/**
|
||||
* 单个中文汉字
|
||||
*/
|
||||
String CHINESE = "[\u4E00-\u9FFF]";
|
||||
/**
|
||||
* 中文汉字
|
||||
*/
|
||||
String CHINESES = CHINESE + "+";
|
||||
/**
|
||||
* 分组
|
||||
*/
|
||||
String GROUP_VAR = "\\$(\\d+)";
|
||||
/**
|
||||
* IP v4
|
||||
*/
|
||||
String IPV4 = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b";
|
||||
/**
|
||||
* IP v6
|
||||
*/
|
||||
String IPV6 = "(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))";
|
||||
/**
|
||||
* 货币
|
||||
*/
|
||||
String MONEY = "^(\\d+(?:\\.\\d+)?)$";
|
||||
/**
|
||||
* 邮件,符合RFC 5322规范,正则来自:http://emailregex.com/
|
||||
* What is the maximum length of a valid email address? https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address/44317754
|
||||
* 注意email 要宽松一点。比如 jetz.chong@hutool.cn、jetz-chong@ hutool.cn、jetz_chong@hutool.cn、dazhi.duan@hutool.cn 宽松一点把,都算是正常的邮箱
|
||||
*/
|
||||
String EMAIL = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])";
|
||||
/**
|
||||
* 移动电话
|
||||
*/
|
||||
String MOBILE = "(?:0|86|\\+86)?1[3-9]\\d{9}";
|
||||
/**
|
||||
* 中国香港移动电话
|
||||
* eg: 中国香港: +852 5100 4810, 三位区域码+10位数字, 中国香港手机号码8位数
|
||||
* eg: 中国大陆: +86 180 4953 1399,2位区域码标示+13位数字
|
||||
* 中国大陆 +86 Mainland China
|
||||
* 中国香港 +852 Hong Kong
|
||||
* 中国澳门 +853 Macao
|
||||
* 中国台湾 +886 Taiwan
|
||||
*/
|
||||
String MOBILE_HK = "(?:0|852|\\+852)?\\d{8}";
|
||||
/**
|
||||
* 中国台湾移动电话
|
||||
* eg: 中国台湾: +886 09 60 000000, 三位区域码+号码以数字09开头 + 8位数字, 中国台湾手机号码10位数
|
||||
* 中国台湾 +886 Taiwan 国际域名缩写:TW
|
||||
*/
|
||||
String MOBILE_TW = "(?:0|886|\\+886)?(?:|-)09\\d{8}";
|
||||
/**
|
||||
* 中国澳门移动电话
|
||||
* eg: 中国台湾: +853 68 00000, 三位区域码 +号码以数字6开头 + 7位数字, 中国台湾手机号码8位数
|
||||
* 中国澳门 +853 Macao 国际域名缩写:MO
|
||||
*/
|
||||
String MOBILE_MO = "(?:0|853|\\+853)?(?:|-)6\\d{7}";
|
||||
/**
|
||||
* 座机号码
|
||||
*/
|
||||
String TEL = "0\\d{2,3}-[1-9]\\d{6,7}";
|
||||
/**
|
||||
* 座机号码+400+800电话
|
||||
*
|
||||
* @see <a href="https://baike.baidu.com/item/800">800</a>
|
||||
*/
|
||||
String TEL_400_800 = "0\\d{2,3}[\\- ]?[1-9]\\d{6,7}|[48]00[\\- ]?[1-9]\\d{6}";
|
||||
/**
|
||||
* 18位身份证号码
|
||||
*/
|
||||
String CITIZEN_ID = "[1-9]\\d{5}[1-2]\\d{3}((0\\d)|(1[0-2]))(([012]\\d)|3[0-1])\\d{3}(\\d|X|x)";
|
||||
/**
|
||||
* 邮编,兼容港澳台
|
||||
*/
|
||||
String ZIP_CODE = "^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[0-7]|6[0-7]|7[0-5]|8[0-9]|9[0-8])\\d{4}|99907[78]$";
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
String BIRTHDAY = "^(\\d{2,4})([/\\-.年]?)(\\d{1,2})([/\\-.月]?)(\\d{1,2})日?$";
|
||||
/**
|
||||
* URL
|
||||
*/
|
||||
String URL = "[a-zA-z]+://[^\\s]*";
|
||||
/**
|
||||
* Http URL
|
||||
*/
|
||||
String URL_HTTP = "(https://|http://)?([\\w-]+\\.)+[\\w-]+(:\\d+)*(/[\\w- ./?%&=]*)?";
|
||||
/**
|
||||
* 中文字、英文字母、数字和下划线
|
||||
*/
|
||||
String GENERAL_WITH_CHINESE = "^[\u4E00-\u9FFF\\w]+$";
|
||||
/**
|
||||
* UUID
|
||||
*/
|
||||
String UUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
||||
/**
|
||||
* 不带横线的UUID
|
||||
*/
|
||||
String UUID_SIMPLE = "^[0-9a-fA-F]{32}$";
|
||||
/**
|
||||
* MAC地址正则
|
||||
*/
|
||||
String MAC_ADDRESS = "((?:[a-fA-F0-9]{1,2}[:-]){5}[a-fA-F0-9]{1,2})|0x(\\d{12}).+ETHER";
|
||||
/**
|
||||
* 16进制字符串
|
||||
*/
|
||||
String HEX = "^[a-fA-F0-9]+$";
|
||||
/**
|
||||
* 时间正则
|
||||
*/
|
||||
String TIME = "\\d{1,2}:\\d{1,2}(:\\d{1,2})?";
|
||||
/**
|
||||
* 中国车牌号码(兼容新能源车牌)
|
||||
*/
|
||||
String PLATE_NUMBER =
|
||||
//https://gitee.com/loolly/hutool/issues/I1B77H?from=project-issue
|
||||
"^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[ABCDEFGHJK])|([ABCDEFGHJK]([A-HJ-NP-Z0-9])[0-9]{4})))|" +
|
||||
//https://gitee.com/loolly/hutool/issues/I1BJHE?from=project-issue
|
||||
"([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]\\d{3}\\d{1,3}[领])|" +
|
||||
"([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$";
|
||||
|
||||
/**
|
||||
* 社会统一信用代码
|
||||
* <pre>
|
||||
* 第一部分:登记管理部门代码1位 (数字或大写英文字母)
|
||||
* 第二部分:机构类别代码1位 (数字或大写英文字母)
|
||||
* 第三部分:登记管理机关行政区划码6位 (数字)
|
||||
* 第四部分:主体标识码(组织机构代码)9位 (数字或大写英文字母)
|
||||
* 第五部分:校验码1位 (数字或大写英文字母)
|
||||
* </pre>
|
||||
*/
|
||||
String CREDIT_CODE = "^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$";
|
||||
/**
|
||||
* 车架号
|
||||
* 别名:车辆识别代号 车辆识别码
|
||||
* eg:LDC613P23A1305189
|
||||
* eg:LSJA24U62JG269225
|
||||
* 十七位码、车架号
|
||||
* 车辆的唯一标示
|
||||
*/
|
||||
String CAR_VIN = "^[A-Za-z0-9]{17}$";
|
||||
/**
|
||||
* 驾驶证 别名:驾驶证档案编号、行驶证编号
|
||||
* eg:430101758218
|
||||
* 12位数字字符串
|
||||
* 仅限:中国驾驶证档案编号
|
||||
*/
|
||||
String CAR_DRIVING_LICENCE = "^[0-9]{12}$";
|
||||
}
|
@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.lang.Holder;
|
||||
import cn.hutool.core.lang.PatternPool;
|
||||
import cn.hutool.core.lang.RegexPool;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
|
||||
@ -29,11 +30,11 @@ public class ReUtil {
|
||||
/**
|
||||
* 正则表达式匹配中文汉字
|
||||
*/
|
||||
public final static String RE_CHINESE = "[\u4E00-\u9FFF]";
|
||||
public final static String RE_CHINESE = RegexPool.CHINESE;
|
||||
/**
|
||||
* 正则表达式匹配中文字符串
|
||||
*/
|
||||
public final static String RE_CHINESES = RE_CHINESE + "+";
|
||||
public final static String RE_CHINESES = RegexPool.CHINESES;
|
||||
|
||||
/**
|
||||
* 正则中需要被转义的关键字
|
||||
|
Loading…
Reference in New Issue
Block a user