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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions

Status
Not open for further replies.

369852

Programmer
May 7, 2002
38
IE
Hi all!!

Could someone point me in the direction of a good tutorial or samples on how to use regular expressions in vb!

Thanks a million
 
i think this came from Msdn ...

' need reference to Microsoft VBScript Regular Expressions
' (vbscript.dll)

Function RegExpTest(patrn, strng) As String
Dim regEx As New RegExp
Dim Match As Match
Dim Matches As MatchCollection ' Create variable.
Dim Sm As SubMatches
Dim RetStr As String
Dim s As String

regEx.Pattern = patrn ' Set pattern.
' regEx.IgnoreCase = True ' Set case
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.

For Each Match In Matches ' Iterate Matches
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCrLf
Next
RegExpTest = RetStr
End Function

Private Sub Form_Load()
MsgBox RegExpTest("ZONE \[(.*)\]", " worker ZONE [ In the Zone ]")
Unload Me
End Sub
 
You might to take a look at the following website


Althought its written with a slant towards JavaScript, it does handle regexp fairly well - for vbScript, you replace the forward slashes with quotes Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi!
I love regular expressions, so I've got a few - most are geared to VBScipt, but if you follow RichardF's suggestion you won't go wrong. The most difficult bit with regular expressions is getting the pattern right.
One final point - IE 5 uses a different script engine than IE 5.5, and there is a difference between how they implement RegExp. Specifically, "non-greedy" matching is not supported in IE5, so use IE 5.5+ or at least download the scripting engine for IE 5.5 from MSDN

Anyway, here are some links





Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top