/**
* 解析地址
*
* @param address
* @return
*/
public static Map<String, String> addressResolution(String address) {
String regex = "(?<province>[^省]+省|.+自治区|(上海|北京|天津|重庆)(市?))*(?<city>[^市]+市|.+自治州|.*?地区|.*?行政单位|.+盟|市辖区)*(?<county>[^县]+县|.+区)*(?<detail>.*)";
Matcher m = Pattern.compile(regex).matcher(address);
String province = null, city = null, county = 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());
county = m.group("county");
row.put("county", county == null ? "" : county.trim());
detail = m.group("detail");
row.put("detail", detail == null ? "" : detail.trim());
table.add(row);
}
Map<String, String> map = null;
for (int i = 0; i < table.size(); i++) {
map = table.get(0);
}
return map;
}
提取地址
最新推荐文章于 2023-12-20 23:00:55 发布