Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Regex Help

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Regex Help
  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 >>
 Regex Help - 7/24/2008 8:20:05 AM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Hey all,

How can I take the resulting output and put it in two seperate vars?


      

So I would want 3740 in one var and 16F8 in another.
 
 
Post #: 1
 
 RE: Regex Help - 7/24/2008 8:38:11 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi esnmb,

your pattern

   "[0-9]{1,}\S[0-9a-zA-Z]"

is wrong (\S is the opposite of \s, there ar more than 1 space between the numbers, the
second part is longer than 1 char), so it matches your data just by accident.

Try this:

Dim objRegEx : Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global     = True
objRegEx.Pattern    = "[0-9]{1,}\S[0-9a-zA-Z]"
objRegEx.Pattern    = "([0-9]{1,})\s+([0-9a-zA-Z]+)"
objRegEx.IgnoreCase = True
Dim strSearchString : strSearchString = "3740   16F8"

Dim colMatches : Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
    Dim strMatch
    For Each strMatch in colMatches
        Wscript.Echo  "|" & strMatch.Value           & "|"
        Wscript.Echo  "|" & strMatch.SubMatches( 0 ) & "|"
        Wscript.Echo  "|" & strMatch.SubMatches( 1 ) & "|"
    Next
End If

Good luck!

ehvbs

(in reply to esnmb)
 
 
Post #: 2
 
 RE: Regex Help - 7/24/2008 11:57:01 PM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Perfect!  Regular Expressions are so confusing to me.  I just don't use them enough I guess.

Thanks!!

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: Regex Help - 7/25/2008 1:45:55 AM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
If my search string is

      

Will the same code apply to get the pid and the '3D0555'?
It works, but I am just trying to make sure it is reliable.  Right now I have my code splitting on ":", but if I can take that extra step out that would be nice.

(in reply to esnmb)
 
 
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 >> Regex Help 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