This page has examples that use VBScript on the client side and thus may not work in any browser but Internet Explorer.
A regular expression is a pattern or sequence of characters that has regular characters and meta-characters. The pattern serves as a template to find (and possibly replace) a desired arrangement in a body of text.
The VBScript RegExp object implements regular expression in a slightly different way than does the JavaScript/JScript RegExp object. Both of these RegExp objects are modeled after regular expressions in PERL.
See the table with the syntax Regular Expression.
Regular expressions are implement in VB/VBScript with the RegExp object.
.Global [ = True | False ]. Read or write. Whether the pattern matches the whole target string (True), or just the first match in the search string (False )..IgnoreCase [ = True | False ]. Read or write. Whether the pattern ignores case (True), or is case sensitive (False )..Multiline. Read or write. Whether the pattern matches before or after "\n" or "\r"(True), or not (False )..Pattern [ = "PatternString" ] . Read or write. The regular expression being searched for.
All of the RegExp methods run the PatternString against the TargetString.
.Execute(TargetString). Returns a Matches collection which has a Match object for each match found in the TargetString.Match object has the following properties:.FirstIndex . Returns position in target string where match occurs..Length . Returns length of match found..Value . Returns value (text) of match found..Replace(TargetString, ReplacingString). Replaces each match with the ReplacingString .Test(TargetString). Returns True if a match was found.This will only work in browsers that support VBS on the client side.
Function VBSRegExpTest(strPattern, strTarget)
Dim regEx, objMatch, objMatches, strReturn
Set regEx = New RegExp
regEx.Pattern = strPattern
regEx.IgnoreCase = True
regEx.Global = True
Set objMatches = regEx.Execute(strTarget)
For Each objMatch in objMatches
strReturn = strReturn & "Match found at position "
strReturn = strReturn & objMatch.FirstIndex & ". Match Value is '"
strReturn = strReturn & objMatch.Value & "'." & vbCRLF
Next
VBSRegExpTest = RetStr
End Function
Function VBSEG()
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
End Function
This will only work in browsers that support VBS on the client side.
Function FintWordCount(strTarget)
Dim regEx, strPattern, intWordCount, objMatches, strReturn
Set regEx = New RegExp
strPattern = "\s"
strTarget = "This sentence has a word count of eight."
regEx.Pattern = strPattern
regEx.Global = True
Set objMatches = regEx.Execute(strTarget)
FintWordCount = objMatches.Count + 1
End Function
Function VBSEG2()
MsgBox(FintWordCount("This sentence has a word count of eight.") & " words counted.")
End Function
Links that lead to off-site pages about RegExp in VB and VBS.
Page Modified: (Hand noted: 2007-10-03 18:38:29Z) (Auto noted: 2008-03-14 19:05:49Z)