Iterating over a Regexp collection

Discussion in 'Scripting' started by goarilla, Nov 2, 2012.

  1. goarilla

    goarilla Guest

    I'm sorry if this is the wrong place to ask this.
    But I can't for the life of me find out why the following
    colMatches object only has one item ?

    I expect the following listing to produce:

    Start Main Sub
    End Main Sub

    and NOT

    Start Main Sub
    abc def
    End Main Sub


    Option Explicit


    Sub Main
    Wscript.Echo "Start Main Sub"

    Dim re
    Set re = New RegExp

    re.pattern = "(abc) (def)"
    re.Global = True
    re.IgnoreCase = True

    Dim colMatches
    Dim strSource
    strSource = "abc def"

    Set colMatches = re.Execute(strSource)

    Dim objMatch

    Wscript.Echo colMatches.Count

    For Each objMatch in colMatches
    Wscript.Echo objMatch.Value

    Wscript.Echo "End Main Sub"
    Wscript.Quit 0

    End Sub
    goarilla, Nov 2, 2012
    1. Advertisements

  2. goarilla

    goarilla Guest


    I apologise for this case of posting before thinking, the answer to my question is perfectly answered by this webpage:, which I was studying at the time.
    goarilla, Nov 20, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.