Matching multiple strings in RegExp

I want to use VB rebexp regular expressions object to match multiple strings with different structure.  e.g. In "37g" I want to match "37" as one string and "g".  I tried:

  objRE.Pattern = "([0-9]+)([a-z]+)"
  objRE.Global = True
  Set objMatches = objRE.Execute(SizeString)

but objMatches.count always comes back as 1 and the match is "37g"

I thought that by using two sets of brackets I should get two matches in the objMatches collection (that's what it implies on MSDN: "Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matches collection, using Item [0]...[n]. To match parentheses characters ( ), use "\(" or "\)".")

Dan
LVL 1
danpidAsked:
Who is Participating?
 
mvidasConnect With a Mentor Commented:
Hi Dan,
you could try the | symbol, meaning OR in regexp.

objRE.Pattern = "([0-9]+)|([a-z]+)"

objRE.Pattern = "\d{2}|[a-z]{1}"      will also have the same affect, will consider a match to be either 2 digits or one lower case letter

Matt
0
 
danpidAuthor Commented:
Thanks Matt.  VB seems to have a different approach to regex to that which I am used to (from perl etc).

\d is handy too
0
 
mvidasCommented:
Not a problem, I'm used to it in VBA for excel, but its the same thing.  Thanks for the grade!
Matt
0
All Courses

From novice to tech pro — start learning today.