Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vba regex only returns first match

Tags:

regex

vba

my regex match in VBA (WORD) only gives one result.

I created this function

Function RE6(strData As String) As String

    Dim RE As Object, REMatches As Object
    Set RE = CreateObject("vbscript.regexp")
    With RE
        .MultiLine = False
        .Global = False
        .IgnoreCase = True
        .Pattern = "\[substep [a-zA-Z]\](.*?); {1}"
    End With

    Set REMatches = RE.Execute(strData)

    RE6 = ""


End Function

The problem here is that it only gives the first result. For example I got a string:

[step 1] title for substeps;  [substep a] step a; [substep b] step b; [substep c] step c; 

My result is:

[substep a] step a;

only 1 match, not the step b and c.

like image 829
Vince V. Avatar asked Sep 06 '12 13:09

Vince V.


1 Answers

You need to set Global to True

http://msdn.microsoft.com/en-us/library/tdte5kwf%28v=vs.84%29

like image 85
marg Avatar answered Sep 22 '22 04:09

marg