Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Code to extract Email addresses from text

Posted by Jean Paul on February 27, 2012


public List<string> GetEmailsFromText(string text)
{
            Regex regex = new Regex(@”[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}”, RegexOptions.IgnoreCase);
            Match match = null;

            List<string> results = new List<string>();
            for (match = regex.Match(text); match.Success; match = match.NextMatch())
                if (!(results.Contains(match.Value)))
                    results.Add(match.Value);

            return results;
}

// Try using GetEmailsFromText(“email@yahoo.com, email2@gmail.com, email3@hotmail.com”);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s