VBA RegEx get Email Address from value

VBA to extract an email address from a string value.  Uses RegEx to find the email pattern following string@email.com format.  Will find any email that matches that pattern and extract the email address.


checkValue = "Dear Dylan, How are you?  dylan@gmail.com"
Dim varResults As Object
Dim varEach
Dim lng As Long
Set regEx = CreateObject("vbscript.RegExp")
regEx.Pattern = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"
regEx.IgnoreCase = True 'True to ignore case
regEx.Global = True 'True matches all occurances, False matches the first occurance
If regEx.Test(checkValue) Then
Set varResults = regEx.Execute(checkValue)
For lng = 1 To varResults.Count
ExtractEmail = ExtractEmail & varResults.Item(lng - 1).Value & "|||"
ExtractEmail = Left(ExtractEmail, Len(ExtractEmail) - Len("|||"))
ExtractEmail = Join(Split(ExtractEmail, "|||"), ", ")
End If
Cells(i, 2).Value = ExtractEmail
ExtractEmail = ""