public class AddressResolutionUtil{
/**
* 解析地址
* @author lin
* @param address
* @return
*/
public static List
String regex="(?
Matcher m=Pattern.compile(regex).matcher(address);
String province=null,city=null,county=null,town=null,village=null;
List
Map
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());
table.add(row);
}
return table;
}
public static void main(String[] args) {
//最初的
//String regex="(?
//除了省市,其他都放详细地址里面
//String regex="(?
String regex="(?
Matcher m=Pattern.compile(regex).matcher("湖北省武汉市武昌区徐东大街岳家嘴电信英特小区9栋3单元601室");
String province=null,city=null,county=null,town=null,village=null;
List
Map
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());
table.add(row);
}
System.out.println(table);
}
}