Java根据身份证号码提取出省市区,JSON数据格式

package com.rdes.talents.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;

/**
 * @Author: 更多实用源码  www.cx1314.cn
 * @Date: 2023/9/7 15:22
 * @Description:  根据身份证号码所在地址提取出省市区
 */
public class AddressResolutionUtil {

    public static List<Map<String, String>> addressResolution(String address) {
        String regex = "(?<province>[^省]+自治区|.*?省|.*?行政区|.*?市)(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?<district>[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?<town>[^区]+区|.+镇)?(?<detail>.*)";
        Matcher m = Pattern.compile(regex).matcher(address);
        String province = null, city = null, district = null, town = null, detail = 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());
            district = m.group("district");
            row.put("district", district == null ? "" : district.trim());
            town = m.group("town");
            row.put("town", town == null ? "" : town.trim());
            detail = m.group("detail");
            row.put("detail", detail == null ? "" : detail.trim());
            table.add(row);
        }
        return table;
    }

    public static void main(String[] args) {
        System.out.println(addressResolution("广东省深圳市福田区梅林街道办事处国际金融科技大厦"));
        System.out.println(addressResolution("山东省德州市禹城市伦镇堂子街村235号"));
        System.out.println(addressResolution("更多精品IT资源 www.cx1314.cn     "));

System.out.println(addressResolution("身份证匹配户籍地址JSON数据下载地址: www.cx1314.cn "));


}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值