1.身份证号/车牌号/手机号的正则表达式
String phoneVerify = "(1|861)(3|5|8)\\d{9}$*";
String idCardVerify = "([1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx])|([1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3})";
String CarNumberVerify = "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$";
2.获取信息的代码:
content是需要解析的字符串,Verify是正则表达式
public List<String> getData(String content, String Verify) {
List<DataTargetMapper> mappers = new ArrayList<>();
Pattern pattern = Pattern.compile(Verify);
Matcher matcher = pattern.matcher(content);
StringBuilder bf = new StringBuilder();
while (matcher.find()) {
mappers.add(matcher.group());
}
int len = bf.length();
if (len > 0) {
bf.deleteCharAt(len - 1);
}
//去空
mappers.removeIf(Objects::isNull);
return mappers;
}