[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Matching multiple strings in RegExp

Posted on 2004-08-19
3
Medium Priority
?
327 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 600 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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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