Advertisement
gospod1978

Regular Expression/Extract emails

Oct 11th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Text.RegularExpressions;
  8.  
  9.  
  10. namespace Orders
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             var pattern = @"^[a-zA-Z0-9][\w-.]+@[a-zA-Z][a-zA-Z-]*(\.[a-zA-Z]+[a-zA-Z-]*?)+$";
  17.             var regex = new Regex(pattern);
  18.  
  19.             var input = Console.ReadLine().Split().Select(x => x.TrimEnd(".,;:!?".ToCharArray()));
  20.  
  21.             foreach (var item in input)
  22.             {
  23.                 if (Regex.IsMatch(item, pattern))
  24.                 {
  25.                     Console.WriteLine(item);
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement