VB中正则表达式的SubMatches、matches和MatchCollection的使用
2008-10-07 14:52
246 查看
今天工作使用到,所以就解决了这个问题,标记下来:
Dim reInfo As RegExp '正则对象
Dim MatchInfo As MatchCollection, objMatch As Match, objSubMatch As SubMatches
……
Set MatchInfo = reInfo.Execute(ShopInfo) 'MatchInfo是结果集合
Set objMatch = MatchInfo.Item(1) 'objMatch是单个的返回结果
Set objSubMatch = objMatch.SubMatches 'objSubMatch是子结果集合,当pattern使用扩号时扩号的匹配项将保存在objSubMatch里。
Me.MSFlexGrid.TextMatrix(r, 1) = objSubMatch(1)
如:strPattern = "<b>(别名|地址|电话)/:</b> (.+)<br />"
匹配:<b>电话:</b> 010-640718<br />
结果:objSubMatch(0) = 电话 objSubMatch(1) = 010-640718 objMatch ="<b>电话:</b> 010-640718<br />"
Dim reInfo As RegExp '正则对象
Dim MatchInfo As MatchCollection, objMatch As Match, objSubMatch As SubMatches
……
Set MatchInfo = reInfo.Execute(ShopInfo) 'MatchInfo是结果集合
Set objMatch = MatchInfo.Item(1) 'objMatch是单个的返回结果
Set objSubMatch = objMatch.SubMatches 'objSubMatch是子结果集合,当pattern使用扩号时扩号的匹配项将保存在objSubMatch里。
Me.MSFlexGrid.TextMatrix(r, 1) = objSubMatch(1)
如:strPattern = "<b>(别名|地址|电话)/:</b> (.+)<br />"
匹配:<b>电话:</b> 010-640718<br />
结果:objSubMatch(0) = 电话 objSubMatch(1) = 010-640718 objMatch ="<b>电话:</b> 010-640718<br />"
相关文章推荐
- [ 转]C# 中使用正则表达式 Regex.Matches方法的几个应用
- no matches found (正则表达式使用中常见错误)
- C# 中使用正则表达式 Regex.Matches方法的几个应用[转]
- vb中使用正则表达式
- VB.net中使用正则表达式验证邮箱地址是否合法
- vb中使用正则表达式
- C# 中使用正则表达式 Regex.Matches方法的几个应用
- matches 正则表达式的使用 编写代码,验证手机号码,并告知用户是"189""158""130" 号段各自的运营公司, 如果号码长度有误,告诉用户手机号码 不存在。
- 在VB中使用正则表达式
- VB.NET使用正则表达式:只取中文并替换多余空格
- VB/VBA 正则表达式的使用方法
- vb中使用正则表达式
- 如何在VB中使用正则表达式
- 在c语言中使用正则表达式
- Java中正则表达式使用方法详解
- Java中正则表达式的使用
- scanf()正则表达式的使用
- ue中使用正则表达式来替换-正则表达式-的捕获组与非捕获组
- VB代码(\D 正则表达式去掉数字)
- Delphi正则表达式使用方法(TPerlRegEx)