Private Sub Form_Load() MsgBox (SearchReplaceRegX("This is RegX demo. <span>VB Stuff is kool VC also kool and ASP dam Kool</span>. Try it" _ , "\b(VB|VC|ASP)\b" _ , "<A HREF='http://www.google.com/q=$1'>$1</A>"))
MsgBox (RegExpTest("is.", "IS1 is2 IS3 is4"))
MsgBox (SubMatchTest("Please send mail to dragon@xyzzy.com. Thanks!")) End Sub
Function SearchReplaceRegX(inputStr, SearchPattern, ReplacePattern) As String Dim str, objRegExp str = inputStr Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Global = True
objRegExp.Pattern = SearchPattern
str = objRegExp.Replace(str, ReplacePattern) SearchReplaceRegX = str
End Function
Function SubMatchTest(inpStr) Dim oRe, oMatch, oMatches Set oRe = CreateObject("VBScript.RegExp")
oRe.Pattern = "(\w+)@(\w+)\.(\w+)" Set oMatches = oRe.Execute(inpStr)
Set oMatch = oMatches(0) retStr = "Email address is: " & oMatch & vbNewLine retStr = retStr & "Email alias is: " & oMatch.SubMatches(0) retStr = retStr & vbNewLine retStr = retStr & "Organization is: " & oMatch.SubMatches(1) SubMatchTest = retStr End Function
Function RegExpTest(patrn, strng) Dim regEx, Match, Matches, I Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = patrn regEx.IgnoreCase = True regEx.Global = True
Set Matches = regEx.Execute(strng) For Each Match In Matches I = I + 1 retStr = retStr & "Match " & I & " found at position " retStr = retStr & Match.FirstIndex & ". Match Value is " retStr = retStr & Match.Value & "'." & vbCrLf Next RegExpTest = retStr End Function |