const reg_address = "(?<province>[^省]+自治区|.*?省|.*?行政区|.*?市)(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?<county>[^县]+县|.+?(区{1})|.+市|.+旗|.+海域|.+岛)?(?<village>.*)";
var formattAddress = (str) => {
if (!str) return
const municipality = ['重庆', '北京', '上海', '天津']
const subStr = str.substring(0, 2)
const isExist = municipality.includes(subStr)
if (isExist) {
str = str.substring(2, str.length - 1)
str = `${subStr}省${str}`
}
let addr = str.match(reg_address)
if (!addr) return
const groups = Object.assign({}, addr.groups)
if (isExist) {
groups.province = groups.province.replace('省', '')
}
return groups
}
formattAddress('重庆重庆市梁平区和林镇三xxx')
formattAddress('香港行政区香港市梁平区和林镇三xxx')