ZQN
2024-06-17 b1ff19545212508d3f65741ab889f0b6df82a511
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
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;
    }
 
 
}