Discussion:
Iterating over a Regexp collection
(too old to reply)
g***@gmail.com
2012-11-02 21:40:27 UTC
Permalink
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
2
abc
def
End Main Sub

and NOT

Start Main Sub
1
abc def
End Main Sub

------------------------

Option Explicit

Main

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
Next

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

End Sub
g***@gmail.com
2012-11-20 11:42:20 UTC
Permalink
Post by g***@gmail.com
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 ?
[snip]

I apologise for this case of posting before thinking, the answer to my question is perfectly answered by this webpage: http://www.regular-expressions.info/vbscript.html, which I was studying at the time.
Loading...