' 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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.