Strip email addresses from HTML or Text with C#.
This code shows you how to extract email addresses out of text and HTML documents. Some day you may need to strip email address from text, for what reason you would want to do this I leave to you, but hopefully not for spam. You can also find phone numbers, web addresses and other patterned parts of text using this code with some simple modifications. Spammers use methods like this for data mining and stripping email addresses off websites. This just goes to show that you should crypt your email address on any websites you use. Using methods such as myName-at-isp.com can help deter data miners.
using System;
using System.Net;
using System.Text.RegularExpressions;
namespace StripEmailAddresses
{
///
/// Description of StripEmail.
///
public class StripEmail
{
public StripEmail()
{
}
public string stripEmails(string url)
{
//WebClient wc1 = new WebClient();
//string htmlData = wc1.DownloadString(url);
string emails="";
Regex re = new Regex("\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b");
MatchCollection mc = re.Matches("jim@whatever.com\r\nxxx@1234.com\r\n\r\n");
foreach( Match m in mc)
{
emails += m.Value.ToString();
}
return emails;
}
}
}

hey!!! any emails??
It should pick up any properly linked email address or regular email address in text.
Pretty interesting code. I think it will be helpful for my juniors who are still getting their programming concepts cleared.