Solved

Matching multiple strings in RegExp

Posted on 2004-08-19
3
321 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:danpid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 150 total points
ID: 11840413
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
 
LVL 1

Author Comment

by:danpid
ID: 11840678
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
 
LVL 35

Expert Comment

by:mvidas
ID: 11841139
Not a problem, I'm used to it in VBA for excel, but its the same thing.  Thanks for the grade!
Matt
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question