Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Iterating over a Regexp collection

11 views
Skip to first unread message

goar...@gmail.com

unread,
Nov 2, 2012, 5:40:27 PM11/2/12
to


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

goar...@gmail.com

unread,
Nov 20, 2012, 6:42:20 AM11/20/12
to
On Friday, November 2, 2012 10:40:27 PM UTC+1, goar...@gmail.com wrote:
> 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.
0 new messages