MiroslavKisov

ExtractEmails

Oct 29th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _01.ExtractEmails
  9. {
  10.     public class StartUp
  11.     {
  12.         public static void Main()
  13.         {
  14.             string emails = Console.ReadLine();
  15.             string pattern = @"([\w.-]+\@[A-Za-z-]+)(\.[a-zA-Z]+)+";
  16.             Regex regex = new Regex(pattern);
  17.             MatchCollection matches = regex.Matches(emails);
  18.             foreach (Match match in matches)
  19.             {
  20.                 string result = match.ToString();
  21.                 if (!(result.StartsWith("-")||result.StartsWith("_")||result.StartsWith(".")
  22.                    || result.EndsWith("-")||result.EndsWith("_")||result.EndsWith(".")))
  23.                 {
  24.                     Console.WriteLine(result);
  25.                 }
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment