|
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.ReUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
@ -33,26 +34,21 @@ public class VehicleLicenseService { |
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
String input = "中华人民共和国机动车行驶证Veltele Lleenseor tPeopiesRepubhlear China号牌导码号牌号码_冀A4647W鄂A4647W档案编号130111431982PlateNo车辆类型Yeeer-Tyie重型半挂牵引车所有人核定较人数2人石家庄畅宇汽车运输有限公司总质量住址河北省石家压市泉区上江镇韩庄村永来街香巷3号整质8870kg核定载所证Adurexs使用性质外尺寸.7400×2550×3560mm准本H2频量48000kg货运昂牌型号Midet解放牌CA4250P66M25T1E6备强制报废期止:2039-11-01河北省石家车辆调润代号NIALFWSRX9L8RIF18215庄市公安局发动机号码ON54120098检验有效期至2025年11月冀A交通管理局注册扫期检验记录RepeierDus2024-11-01发证日期2024-11-91天然气lsueDate300051111965"; |
|
|
|
|
|
|
|
|
|
// 正则表达式匹配“代号”后以L开头的17位字母数字组合
|
|
|
|
|
Pattern pattern = Pattern.compile("代号.*?(L[A-Za-z0-9]{16})"); |
|
|
|
|
Matcher matcher = pattern.matcher(input); |
|
|
|
|
|
|
|
|
|
if (matcher.find()) { |
|
|
|
|
String code = matcher.group(1); |
|
|
|
|
System.out.println("匹配到的代号: " + code); // 输出:LFWSRX9L8RIF18215
|
|
|
|
|
} else { |
|
|
|
|
System.out.println("未找到符合要求的代号"); |
|
|
|
|
} |
|
|
|
|
List<String> texts = Arrays.asList(input.split("\\s+")); |
|
|
|
|
String s = extractPlateNo(texts); |
|
|
|
|
System.out.println(s); |
|
|
|
|
} |
|
|
|
|
public Map<String, Object> extractVehicleLicenseInfo(List<String> texts) { |
|
|
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
data.put("licensePlate", extractPlateNo(texts)); |
|
|
|
|
String text = String.join("", texts) |
|
|
|
|
.replaceAll("2925-", "2025-") |
|
|
|
|
.replaceAll("2924-", "2024-") |
|
|
|
|
.replaceAll("2625-", "2025-") |
|
|
|
|
.replaceAll("2624-", "2024-") |
|
|
|
|
.replaceAll("\\.", ""); |
|
|
|
|
data.put("licensePlate", extractPlateNo(text)); // 冀A4336E
|
|
|
|
|
|
|
|
|
|
data.put("vehicleVin", extractVin(text)); // LFWSRX9L2RIF17688
|
|
|
|
|
data.put("userAddress", extractAddress(text)); // 河北省石家庄市鹿泉区上庄镇韩庄村永乐街芳香巷3号
|
|
|
|
|
data.put("commissionDate", extractIssueDate(text)); // 2024-11-01
|
|
|
|
|
@ -75,8 +71,8 @@ public class VehicleLicenseService { |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
private static String extractPlateNo(List<String> texts) { |
|
|
|
|
|
|
|
|
|
private static String extractPlateNo(String text) { |
|
|
|
|
// 综合正则表达式(覆盖所有常见车牌类型)
|
|
|
|
|
String regex = |
|
|
|
|
"(?<![0-9A-Z])" // 前导边界控制
|
|
|
|
|
@ -90,12 +86,13 @@ public class VehicleLicenseService { |
|
|
|
|
+ "|([使领]\\d{6})" // 使馆车牌
|
|
|
|
|
+ ")" |
|
|
|
|
+ "(?![0-9A-Z]))"; // 后续边界控制
|
|
|
|
|
|
|
|
|
|
// 执行匹配
|
|
|
|
|
Matcher matcher = Pattern.compile(regex).matcher(text); |
|
|
|
|
if (matcher.find()) { |
|
|
|
|
// 清洗分隔符并返回
|
|
|
|
|
return matcher.group().replaceAll("[·\\s]", "").replaceAll("O", "0"); |
|
|
|
|
for (String text : texts) { |
|
|
|
|
// 执行匹配
|
|
|
|
|
Matcher matcher = Pattern.compile(regex).matcher(text); |
|
|
|
|
if (matcher.find()) { |
|
|
|
|
// 清洗分隔符并返回
|
|
|
|
|
return matcher.group().replaceAll("[·\\s]", "").replaceAll("O", "0"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|