比如: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
就是通过序号!