Created
April 27, 2018 09:57
-
-
Save pykong/d32df34f6d804d61162ac5a84ee96df1 to your computer and use it in GitHub Desktop.
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
internal static class MailExtractor | |
{ | |
public static List<string> ExtractEmails(string data) | |
{ | |
List<string> ExtractedEmailAddresses = new List<string>(); | |
//instantiate with this pattern | |
string EmailPattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; | |
Regex emailRegex = new Regex(EmailPattern, RegexOptions.IgnoreCase); | |
//find items that matches with our pattern | |
MatchCollection emailMatches = emailRegex.Matches(data); | |
foreach (Match emailMatch in emailMatches) | |
{ | |
ExtractedEmailAddresses.Add(emailMatch.Value); | |
} | |
return ExtractedEmailAddresses.Distinct().ToList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment