Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Match formula to match values in multiple columns K[_2_] Excel Discussion (Misc queries) 2 April 22nd 10 10:22 AM
MATCH working but not.... Hile Excel Worksheet Functions 6 July 30th 08 07:53 AM
MATCH Multiple Criteria & Return Previous / Penultimate Match Sam via OfficeKB.com Excel Worksheet Functions 27 October 6th 07 01:39 AM
MATCH not working David Excel Worksheet Functions 5 February 12th 07 11:23 PM


All times are GMT +1. The time now is 03:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"