【正規表現】


Dim sSearchPattern As String
Dim sTargetStr As String
 
Dim iMatchIdx As Integer
Dim iSubMatchIdx As Integer
 
Dim oMatchResult As Object
Dim oRegExp As Object
Set oRegExp = CreateObject("VBScript.RegExp")
 
sSearchPattern = "(\w+)\((\w+) (\w+)\)"
sTargetStr = "TestFunc01(char aaa) TestFunc02(int bbb)"
 
oRegExp.Pattern = sSearchPattern               '検索パターンを設定
oRegExp.IgnoreCase = True                      '大文字と小文字を区別しない
oRegExp.Global = True                          '文字列全体を検索
Set oMatchResult = oRegExp.Execute(sTargetStr) 'パターンマッチ実行

Debug.Print oMatchResult.Count
For iMatchIdx = 0 To oMatchResult.Count - 1
    Debug.Print oMatchResult(iMatchIdx).SubMatches.Count
    For iSubMatchIdx = 0 To oMatchResult(iMatchIdx).SubMatches.Count - 1
        Debug.Print oMatchResult(iMatchIdx).SubMatches(iSubMatchIdx)
    Next iSubMatchIdx
Next iMatchIdx
 

最終更新:2015年03月04日 21:52