dotnet-Snippets.com
Snippets: 73 | Registered User: 84 | Visitors online: 31
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Get all email addresses from text or string

Author: Tim Hartwig
Programming Language: VB.NET Rating:
not yet rated

Views: 5288

Description:

This function can filter all email addresses out of a string and save's them into a List(Of String)


kick it on DotNetKicks.com




Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Public Function GetAllEMailAddresses(ByVal Input As String) As List(Of String)
    Dim Results As New List(Of String)


    Dim MC As Text.RegularExpressions.MatchCollection = _
    System.Text.RegularExpressions.Regex.Matches(Input, _
    "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")

    For i As Integer = 0 To MC.Count - 1
        If Results.Contains(MC(i).Value) = False Then
            Results.Add(MC(i).Value)
        End If
    Next

    Return Results
End Function



Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)

wekempf wrote on: 22.09.2008

Regular expressions are notoriously bad for use in validating/searching e-mail addresses. This one in particular is extremely buggy. There is a supposedly valid regex for this, but the code is extremely scary. Best just not to do this.