package com.project.common.utils;
|
|
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
/**
|
* 身份证地址提取省市区工具类
|
*/
|
public class AddressResolutionUtil {
|
|
/**
|
* 根据身份证地址提取省市区工具类
|
*
|
* @param address
|
* @return
|
*/
|
public static List<Map<String, String>> addressResolution(String address) {
|
String regex = "(?<province>[^省]+自治区|.*?省|.*?行政区|.*?市)(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?<district>[^县]+县|[^社]+区|[^社]+市|[^旗]+旗|[^社]+海域|[^社]+岛)";
|
Matcher m = Pattern.compile(regex).matcher(address);
|
String province = null, city = null, area = null;
|
List<Map<String, String>> table = new ArrayList<Map<String, String>>();
|
Map<String, String> row = null;
|
while (m.find()) {
|
row = new LinkedHashMap<String, String>();
|
province = m.group("province");
|
row.put("province", province == null ? "" : province.trim());
|
city = m.group("city");
|
row.put("city", city == null ? "" : city.trim());
|
area = m.group("district");
|
row.put("area", area == null ? "" : area.trim());
|
|
table.add(row);
|
}
|
return table;
|
}
|
|
|
}
|