【正規表現(VBS版)】


実行例

Dim sSearchPattern
Dim sTargetStr
sSearchPattern = "((\w+)\((\w+) (\w+)\))"
sTargetStr = "TestFunc01(char aaa) TestFunc02(int bbb)"
 
Dim oRegExp
Set oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Pattern = sSearchPattern                '検索パターンを設定
oRegExp.IgnoreCase = True                       '大文字と小文字を区別しない
oRegExp.Global = True                           '文字列全体を検索

Dim oMatchResult
Set oMatchResult = oRegExp.Execute(sTargetStr)  'パターンマッチ実行

Dim iMatchIdx
Dim iSubMatchIdx
Dim sOutStr
sOutStr = "マッチ数:" & oMatchResult.Count
For iMatchIdx = 0 To oMatchResult.Count - 1
    sOutStr = sOutStr & vbNewLine & "サブマッチ数:" & oMatchResult(iMatchIdx).SubMatches.Count
    For iSubMatchIdx = 0 To oMatchResult(iMatchIdx).SubMatches.Count - 1
        sOutStr = sOutStr & " " & oMatchResult(iMatchIdx).SubMatches(iSubMatchIdx)
    Next
Next
 
MsgBox sOutStr
'【出力結果】
' マッチ数:2
' サブマッチ数:4 TestFunc01(char aaa) TestFunc01 char aaa
' サブマッチ数:4 TestFunc02(int bbb) TestFunc02 int bbb

最終更新:2016年10月21日 15:08