troubleshooting Question

Modify vba function

Avatar of SAbboushi
SAbboushiFlag for United States of America asked on
Visual Basic ClassicOutlookVB Script
4 Comments1 Solution801 ViewsLast Modified:
Would like the attached code to also handle the following 3 scenarios:

1) S1@W3.com

Desired Result:
Name= ""
Address = "S1@W3.com"

2) S1.test@W3.com
Desired Result:
Name= ""
Address = "S1.test@W3.com"

3) Sam Abboushi <S1.test@W3.com>
Sam Abboushi [S1.test@W3.com]
Sam Abboushi (S1.test@W3.com)
Desired Result:
Name= "Sam Abboushi"
Address = "S1.test@W3.com"

Function splitAddy(str As String) As Variant
Dim regEx As Object
Dim matchCollection As Object

Debug.Print splitAddy("fred smith <fred@fred.com>")(1)
fred@ fred.com
Debug.Print splitAddy("fred smith <fred@fred.com>")(0)
fred smith

    Set regEx = CreateObject("vbscript.regexp")
    With regEx
        .Pattern = "([\w|-]*)[,; ] *([\w|-]*) *(?:[\[|{|(|<])([\w|-]*@[\w|-]*.[\w|-]*)(?:[\]|}|)|>])"
        .Global = True
        .IgnoreCase = True
    End With
    Set matchCollection = regEx.Execute(str)
    If matchCollection.Count = 0 Then
        splitAddy = ""
    Else
        splitAddy = Array(matchCollection(0).submatches(0) & " " & matchCollection(0).submatches(1), matchCollection(0).submatches(2))
    End If

End Function
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros