Hi Im struggling a bit with this, basically I want to find an email address in a message body
i have played with regex but thats not what is needed! As basically I want to search for an Email address in a string not validate one!
Public Function FindEMailAddressesInStr(ByVal StringWithEmails As String) As List(Of String)
Dim emailList As New List(Of String)
Dim RegExMatch As Text.RegularExpressions.MatchCollection = _
System.Text.RegularExpressions.Regex.Matches(StringWithEmails, _
"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
For i As Integer = 0 To RegExMatch.Count - 1
If emailList.Contains(RegExMatch(i).Value) = False Then
emailList.Add(RegExMatch(i).Value)
End If
Next
Return emailList
End Function
Sub Activity_Create(FirstTime As Boolean)
Log(FindEmails($"aasd@sdsdf.com, lkjlk jsdf lksdjf
fewfwe@gfgg.com"$))
End Sub
Sub FindEmails(str As String) As List
Dim m As Matcher = Regex.Matcher("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", str)
Dim res As List
res.Initialize
Do While m.Find
res.Add(m.Match)
Loop
Return res
End Sub
Thanks but from what i read that just validates if a sting contains a correctly formatted email address? not actually finds an email address in a large text file? But
Thanks for your very fast response!
Sub Activity_Create(FirstTime As Boolean)
Log(FindEmails($"aasd@sdsdf.com, lkjlk jsdf lksdjf
fewfwe@gfgg.com"$))
End Sub
Sub FindEmails(str As String) As List
Dim m As Matcher = Regex.Matcher("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", str)
Dim res As List
res.Initialize
Do While m.Find
res.Add(m.Match)
Loop
Return res
End Sub