省市区地址解析C#实现代码
public string Analysis(string address)
{
string regex = @"(?<province>[^省]+自治区|.*?省)?(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市)?(?<county>[^县]+县|[^区]+区|[^市]+市|.+旗|.+海域|.+岛)?(?<town>[^区]+区|.+镇|.+办事处)?(?<village>.*)";
var m = Regex.Match(addr, regex, RegexOptions.IgnoreCase);
var province = m.Groups["province"].Value;//省
var city = m.Groups["city"].Value;//市
var county = m.Groups["county"].Value;//县
var town = m.Groups["town"].Value;//镇
var village = m.Groups["village"].Value;//详细地址
}
成功不是锦上添花,而是变废为宝!