Created
August 28, 2013 21:06
-
-
Save bobixaka/6371291 to your computer and use it in GitHub Desktop.
How to extract e-mails from a text file with Regex (Regular expression)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
namespace Task_18_E_MailExtract | |
{ | |
class MailExtractor | |
{ | |
static void Main() | |
{ | |
StreamReader Input = new StreamReader(@"..\..\InputFile.txt"); | |
string InputContent = ""; | |
StringBuilder Output = new StringBuilder(); | |
string Pattern = @"\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b"; | |
Regex mail = new Regex(Pattern,RegexOptions.IgnoreCase); | |
using (Input) | |
{ | |
InputContent = Input.ReadToEnd(); | |
} | |
MatchCollection MC = mail.Matches(InputContent); | |
foreach (var match in MC) | |
{ | |
Output.AppendLine(match.ToString()); | |
} | |
Console.WriteLine(Output); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment