Regex Multiple Match not working

E

ExcelMonkey

My regex is not identifying multiple matches below. Why is this? I keep
getting a return of 1 instead of 3.

Sub Thing()
Dim x As String
Dim z As Double
x = "The black cat"

z = ReturnWords(x)

End Sub


Private Function ReturnWords(y As String) As Double

Dim objRegExp As Object
Dim Match As Variant
Dim Matches
Dim tempstring As Variant
Dim Counter As Double

Set objRegExp = CreateObject("Vbscript.RegExp")
objRegExp.IgnoreCase = IgnoreCase
objRegExp.MultiLine = MultiLine
objRegExp.Pattern = "\w+" 'words

Set Matches = objRegExp.Execute(y)

ReturnWords = Matches.Count

End Function
 
R

Ron Rosenfeld

My regex is not identifying multiple matches below. Why is this? I keep
getting a return of 1 instead of 3.

Sub Thing()
Dim x As String
Dim z As Double
x = "The black cat"

z = ReturnWords(x)

End Sub


Private Function ReturnWords(y As String) As Double

Dim objRegExp As Object
Dim Match As Variant
Dim Matches
Dim tempstring As Variant
Dim Counter As Double

Set objRegExp = CreateObject("Vbscript.RegExp")
objRegExp.IgnoreCase = IgnoreCase
objRegExp.MultiLine = MultiLine
objRegExp.Pattern = "\w+" 'words

Set Matches = objRegExp.Execute(y)

ReturnWords = Matches.Count

End Function

You probably need to set the Global property of the object to true:

objRegExp.Global = TRUE.
--ron
 
E

ExcelMonkey

Yup that worked. Why?

Thanks

EM

Ron Rosenfeld said:
You probably need to set the Global property of the object to true:

objRegExp.Global = TRUE.
--ron
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top