Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Reg Expressions in VBscript 3

Status
Not open for further replies.

osfan82

Programmer
Feb 11, 2003
6
US
Just wondering if anyone would know the best way to do the following in VBSCRIPT. This is written using PERL, but need the same in VB...

Code:
for (split '\n', $string)
{
   $userID = $1 if /UID\.+\s*(.+)/;
   $fullName = $1 if /Full Name\.+\s*(.+)/;
   #...etc...
}

$string will be an html page read in using ASPTear on the VB side. I just need help with the VB code to go through each line and store certain information into variables for use later.

Thanks!
Troy
 
Well, in VB it might be something like:

Public Sub Example(strSource As String)
Dim re As RegExp
Dim mystring As Variant
Dim UserID As String
Dim FullName As String

Set re = New RegExp

re.Pattern = "UID\.+\s*(.+)"
For Each mystring In Split(strSource, ",")
UserID = ""
FullName = ""
re.Pattern = "UID\.+\s*(.+)"
If re.test(mystring) Then UserID = re.Replace(mystring, "$1")
Debug.Print "UID: "; UserID

re.Pattern = "FullName\.+\s*(.+)"
If re.test(mystring) Then FullName = re.Replace(mystring, "$1")
Debug.Print "FN: "; FullName

Next
Set re = Nothing
End Sub
 
(erm..you don't need the very first re.pattern line that preceeds the loop in the above example)
 
Thanks! Havent Had a chance to test it out yet, but it looks like what I need. One questions though, should the $1 used to refference the tagged value in the pattern be changed to \1?

Thanks Again,
Troy
 
Thanks alot, strongm! I'm a Unix guy now finding his
way more into the Windows word, and I had no idea Perl-like
regexps existed here at all. This is great.

I tried out some code of my own based on your example above
and it works fine. I'm doing this in Access, and there's
no online help on regexps, though I can see the classes/
objects in the Object Browser.

Can you tell me where I might read up a bit on regexps
in VB/VBA? Thanks again.
 
Thanks. I checked out the link above and really didn't
see ANY difference from Perl in the re's themselves.
It's just the OO way of working with them that's
different. (Actually I think even Perl has an OO regexp
module, though I've never used it.)

Thanks alot. Have another star!
 
Thanks Again! Everything is working great. I too have more of a Perl background and was surprised to see that the regular expressions were pretty much the same on the VB side of the house. You get a star! : )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top