VB中正則表達式的SubMatches、matches和MatchCollection的使用

今天工作使用到,所以就解決了這個問題,標記下來:    
    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 />"
發佈了56 篇原創文章 · 獲贊 3 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章