// var address = "辽宁省沈阳市和平区"// 以这个地址为例 // const address = msg.detail // const proExp = ".+[省]",cityExp = ".+[市]",disExp = ".+[区]" // const province = address.match(new RegExp(proExp))// 省 // const city = address.match(new RegExp(cityExp))[0].replace(province, "")// 市 // const district = address.match(new RegExp(disExp))[0].replace(province, "").replace(city, "")// 区var address = '辽宁省沈阳市和平区' // 以这个地址为例
var proExp = '.+[省]', cityExp = '.+[市]', disExp = '.+[区]'
var province = address.match(new RegExp(proExp)) // 省
var city = address.match(new RegExp(cityExp))[0].replace(province, '') // 市
var district = address.match(new RegExp(disExp))[0].replace(province, '').replace(city, '') // 区