Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


regexp match problem

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60192
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> regexp match problem
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 regexp match problem - 5/14/2008 4:01:41 AM   
  yfki

 

Posts: 70
Score: 0
Joined: 12/12/2007
Status: offline
I have a string that will/should contain either a 5 digit number "12345" or a record number that will be something like "ABC_E00012345", separated by whitespace character
I would like to match each individual instance of the 2 possibilities above.
Example String:  12345 ABC_E12345 54321 98765 ABC_E98765 00 123 A

What I would like to match:
12345
ABC_E12345
54321
98765
ABC_E98765

What I would like to discard, or just not return:
00
123
A

The pattern I came up with is returning such things as 00 123 A, can anyone help?

objRegEx.Pattern = "[^\d{5}$]|^ABC_E000[\d{5}$]"

Also, if possible can someone give me the in a nutshell of when and where to use ^ or $ inside or outside bracket/paren

Thanks everyone! 

 
 
Post #: 1
 
 RE: regexp match problem - 5/14/2008 4:10:06 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Dim oRE : Set oRE = New Regexp
Dim strTest
Dim colMatches
Dim oMatch
strTest = "12345 ABC_E12345 54321 98765 ABC_E98765 00 123 A"
oRE.Pattern = "(ABC_E\d{5})|(\d{5})"
oRE.Global = True
Set colMatches = oRE.Execute(strTest)
For Each oMatch In colMatches  
   WScript.Echo oMatch.Value
Next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to yfki)
 
 
Post #: 2
 
 RE: regexp match problem - 5/14/2008 4:47:11 AM   
  yfki

 

Posts: 70
Score: 0
Joined: 12/12/2007
Status: offline
eXcellent!!  but..

If you have 987654321 in the string, it will return 98765, and I only want to match the 5 digit numbers. (not 5 digits within X number digits)

So....
String: 987654321 ABC_E00012345 12345
Return: ABC_E00012345 12345

Which leads me to the next question, can you shed some light on when ^ and $ should be used? and when using them with () or [] when they go inside or outside?

Because I tried to change the pattern to
(ABC_E000\d{5})|(^\d{5}$)   - Which i thought would mean "exactly" a 5 digit number, but no dice....

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: regexp match problem - 5/14/2008 5:15:28 AM   
  dm_4ever


Posts: 2366
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Maybe try...

"(ABC_E\d{5})|(\b\d{5}\b)"

^ = start of entire string or if inside [] then it mean NOT the things you put in there
$  = end of entire string

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to yfki)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> regexp match problem Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts