Wednesday, August 10, 2011

How to Find All Email Address in a Text File





using System.Text.RegularExpressions;
using System.IO;

string FileData = File.ReadAllText(fileName);

Regex emailregex = new Regex("(?<user>[^@]+)@(?<host>.+)");
MatchCollection matches = emailregex .Matches(FileData);
foreach (Match match in matches)
{
      Console.WriteLine(match.Value.ToString());
}

No comments:

Post a Comment