End Function
MsgBox(SubMatchTest("Please send mail to someone@example.com. Thanks!"))
Function SubMatchTest(inpStr) Dim oRe, oMatch, oMatches Set oRe = New RegExp ' Look for an email address (not a perfect RegExp). oRe.Pattern = "(\w+)@(\w+)\.(\w+)" ' Get the Matches collection. Set oMatches = oRe.Execute(inpStr) ' Get the first item in the Matches collection. Set oMatch = oMatches(0) msgbox typename(oMatch) ' Create the results string. ' The Match object is the entire match - someone@example.com. retStr = "Email address is: " & oMatch & vbNewline ' Get the sub-matched parts of the address. ' someone retStr = retStr & "Email alias is: " & oMatch.SubMatches(0) retStr = retStr & vbNewline ' example retStr = retStr & "Organization is: " & oMatch. SubMatches(1) SubMatchTest = retStr
End Function
MsgBox(SubMatchTest("Please send mail to someone@example.com. Thanks!"))Function SubMatchTest(inpStr) Dim oRe, oMatch, oMatches Set oRe = New RegExp ' Look for an email address (not a perfect RegExp). oRe.Pattern = "(\w+)@(\w+)\.(\w+)" ' Get the Matches collection. Set oMatches = oRe.Execute(inpStr) ' Get the first item in the Matches