//地址校验
public static Map addressResolution(String address){
String regex="(?[^省]+自治区|.*?省|.*?行政区|.*?市)(?[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?[^区]+区|.+镇)?(?.*)";
Matcher m= Pattern.compile(regex).matcher(address);
String province=null,city=null,county=null,town=null,village=null;
Map row=null;
while(m.find()){
row=new LinkedHashMap();
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());
town=m.group("town");
row.put("town", town==null?"":town.trim());
village=m.group("village");
row.put("village", village==null?"":village.trim());
}
return row;
}
public static void main(String[] args) {
System.out.println(addressResolution("浙江省杭州市余杭区文一西路亲橙里20栋1025"));
Map xxx = addressResolution("浙江省杭州市余杭区文一西路亲橙里20栋1025");
System.out.println(xxx.get("province"));
}
打印结果
在添加地址时,判断省市区和详细地址是否为空来进行操作