Regex Multiple Match not working
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 |
Regex Multiple Match not working
On Tue, 12 May 2009 11:46:01 -0700, ExcelMonkey
wrote: 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 |
Regex Multiple Match not working
Yup that worked. Why?
Thanks EM "Ron Rosenfeld" wrote: On Tue, 12 May 2009 11:46:01 -0700, ExcelMonkey wrote: 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 |
Regex Multiple Match not working
On Tue, 12 May 2009 13:42:13 -0700, ExcelMonkey
wrote: Yup that worked. Why? Thanks EM Look he http://support.microsoft.com/default...02&Product=vbb --ron |
All times are GMT +1. The time now is 02:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com