Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace ConsoleTests
- {
- class ConsoleTests
- {
- static void Main()
- {
- string input = Console.ReadLine();
- ExtractMails(input);
- }
- public static void ExtractMails(string text)
- {
- const string MatchEmailPattern =
- @"(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
- + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
- + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
- + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})";
- Regex rx = new Regex(MatchEmailPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
- // Find matches.
- MatchCollection matches = rx.Matches(text);
- // Report the number of matches found.
- int noOfMatches = matches.Count;
- // Report on each match.
- foreach (Match match in matches)
- {
- Console.WriteLine(match.Value.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment