回复 1# ivor - ' 样本:江西省上饶市信州区分宜县
-
- ' 优先匹配顺序1.xx市 2. xx区 3.xx县
- ' 前面开头可能没有xx省,开头也可能没有xx市
-
- arr_data = array( "江西省上饶市信州区分宜县", "上饶市信州区分宜县", "信州区分宜县")
- Dim regEx ' 建立变量。
- Set regEx = New RegExp ' 建立正则表达式。
- regEx.Pattern = "(?:\S+省|)(?:(\S+)市|)(\S+)区(\S+)县"
- for each data in arr_data
- Set oMatches = regEx.Execute(data)
- If oMatches.Count > 0 Then
- Set oMatch = oMatches(0)
- msgbox "源数据:" & data & " 市:" & oMatch.SubMatches(0) & " 区:" & oMatch.SubMatches(1) & " 县:" & oMatch.SubMatches(2)
- Else
- msgbox "解析失败"
- End If
- next
复制代码
|