当前位置: 代码迷 >> ASP.NET >> 正则表达式怎么提取地址中的省市?
  详细解决方案

正则表达式怎么提取地址中的省市?

热度:6040   发布时间:2013-02-25 00:00:00.0
正则表达式如何提取地址中的省市???
比如:string   str   = "浙江省杭州市某街道118号 ";
如何利用正则表达式提取出   浙江和杭州
C#

------解决方案--------------------------------------------------------
try

string str = "浙江省杭州市某街道118号 ";
string pro = string.Empty;
string city = string.Empty;
Match m = Regex.Match(str, @ "(? <pro> .*?)省(? <city> .*?)市 ");
if (m.Success)
{
pro = m.Groups[ "pro "].Value;
city = m.Groups[ "city "].Value;
}
------解决方案--------------------------------------------------------
我试了过客。好像取不到。你试试这样应该可以!
Dim address As String = "浙江省杭州市某街道118号 "
Dim pro As String = String.Empty
Dim city As String = String.Empty
Dim m As Match = Regex.Match(address, "(? <pro> .*?)省(? <city> .*?)市 ")
If m.Success Then
pro = m.Groups(1).Value
city = m.Groups(2).Value
End If
就是通过序号!