This page has examples that use VBScript on the client side and thus may not work in any browser but Internet Explorer.

Intro

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.

Properties

Methods

All of the RegExp methods run the PatternString against the TargetString.

EG

EG General

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

EG Word Count

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

Links that lead to off-site pages about RegExp in VB and VBS.

Page Modified: (Hand noted: ) (Auto noted: )