RegexConstants.java
6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package cn.com.glsx.entmicro.constants;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @ClassName RegexConstans
* @Description
* @Author lichongyuan
* @Date 2022/4/11
*/
public class RegexConstants {
/**
* 普通车牌(蓝牌、黄牌)
* * 车牌号码长度:7 位
* * 车牌号码格式:
* * 第1位:省份简称
* * 第2位:发证机关代码
* * 第3位:号码
* * 第4位:号码
* * 第5位:号码
* * 第6位:号码
* * 第7位:号码
* * 省份简称:京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新
* 发证机关代码:ABCDEFGHJKLMNPQRSTUVWXY (无 I, O , Z 三个字母。其中O和Z属于特殊车牌类型)
* 车牌号码:
* 数字:0123456789
*/
public static final String ORDINARY_LICENSE_PLATE_REGEX = "^[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5}$";
/**
* * 新能源车牌(大小车)
*
* 小型新能源汽车号牌的第一位必须使用字母D、F(D表明纯电动新能源汽车,F表明非纯电动新能源汽车),第二位可使用字母或者数字,后四位必须使用数字。
* 大型新能源汽车号牌的前五位必须使用数字,第六位必须使用字母D、F(D表明纯电动新能源汽车,F表明非纯电动新能源汽车)
*/
public static final String NEW_ENERGY_PLATE_REGEX = "^([京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][0-9DF][0-9ABCDEFGHJKLMNPQRSTUVWXYZ]\\d{3}[0-9DF]|[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5})$";
/**
* 武警车牌:
* * 第1位和第2位 允许前两位为大写英文字母
* * 第3-8位 可录入五个或六个字符,由大写英文字母和阿拉伯数字组成,其中第三位可录汉字也可录大写英文字母及阿拉伯数字,
* 第三位也可空,如:WJ警00081、WJ京1234J、WJ1234X。
*/
public static final String WJ_PLATE_REGEX = "^WJ[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]?[0-9a-zA-Z]{5}$";
/**
* 军牌
* * 以两位为大写英文字母开头,后面以5位阿拉伯数字组成。如:BA12345。
*/
public static final String PLA__PLATE_REGEX = "^[军空海北 沈兰南西东中][A-Z]{2}[0-9]{5}$";
/**
* 主要匹配 民用车牌,使领、两地牌
*/
public static final String POLICE_PLATE_REGEX = "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$";
/**
* 车架号 ^[A-Za-z0-9]{17}$ ^([A-HJ-NPR-Z0-9]{8}[X0-9][A-HJ-NPR-Z0-9]{3}[0-9]{5}$) 至少包含一位字母 去除非法I Q O字符 尾数五位纯数字
* ^(?![0-9~@*()_]+$)^([A-Za-z0-9]{17}$) 至少包含一位字母 其余不管
*/
public static final String REGEX_CARVIN = "^(?![0-9~@*()_]+$)^([A-HJ-NPR-Z0-9]{8}[X0-9][A-HJ-NPR-Z0-9]{3}[0-9]{5}$)";
/**
* 手机号
*/
public static final String REGEX_PHONENUM = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
/**
* 匹配特殊符号("英文:~!@#$%^&*()+=|{}':;', 中文:.<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?)
*/
public static final String REGEX_SPLIT = "[\\n`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?\\\\-]";
//
// public static void main(String[] args) {
// String palte = "0000014B3Y3014070 15778727124,车牌号:云AF0011";
// //去特殊符号
// String[] split = palte.split(RegexConstants.REGEX_SPLIT);
// String phone = "15778727124";
// Pattern phoneReg = Pattern.compile(RegexConstants.REGEX_PHONENUM);
// Pattern carVin = Pattern.compile(RegexConstants.REGEX_CARVIN);
// Pattern newCar = Pattern.compile(RegexConstants.NEW_ENERGY_PLATE_REGEX);
// Pattern police = Pattern.compile(RegexConstants.POLICE_PLATE_REGEX);
// Pattern wj = Pattern.compile(RegexConstants.WJ_PLATE_REGEX);
// Pattern ORDINARY = Pattern.compile(RegexConstants.ORDINARY_LICENSE_PLATE_REGEX);
// Pattern pla = Pattern.compile(RegexConstants.PLA__PLATE_REGEX);
// //按找到可以匹配的第一个车牌号为准
// for (String s : split) {
// Matcher carVin_m = carVin.matcher(s);
// Matcher phoneReg_m = phoneReg.matcher(s);
// Matcher newCar_n = newCar.matcher(s);
// Matcher police_m = police.matcher(s);
// Matcher wj_m = wj.matcher(s);
// Matcher ORDINARY_m = ORDINARY.matcher(s);
// Matcher pla_m = pla.matcher(s);
// if (carVin_m.find()) {
// System.out.println("车架号格式正确");
// System.out.println(carVin_m.group());
// }
// if (phoneReg_m.find()) {
// System.out.println("手机号格式正确");
// System.out.println(phoneReg_m.group());
// }
// if (newCar_n.find()) {
// System.out.println("新能源车牌号");
// System.out.println(newCar_n.group());
// }
// if (police_m.find()) {
// System.out.println("警车车牌号格式正确");
// System.out.println(police_m.group());
// }
// if (wj_m.find()) {
// System.out.println("武警车牌号格式正确");
// System.out.println(wj_m.group());
// }
// if (ORDINARY_m.find()) {
// System.out.println("普通车牌格式正确");
// System.out.println(ORDINARY_m.group());
// }
// if (pla_m.find()) {
// System.out.println("军车车牌格式正确");
// System.out.println(pla_m.group());
// }
// }
// }
}