ZhivkoPetkov

Regex - emails

Jun 18th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace C_
  9. {
  10.  
  11.  
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             var input = Console.ReadLine();
  17.  
  18.             string pattern = @"(^|(?<=\s))([a-zA-Z0-9]+)(\.|-|_)?([a-zA-Z0-9]+)@([a-zA-Z]+.)?([a-zA-Z]+.)?([a-zA-Z0-9]+\.[a-zA-Z]+)";
  19.  
  20.             MatchCollection matches = Regex.Matches(input, pattern);
  21.  
  22.             foreach (Match item in matches)
  23.             {
  24.                 Console.WriteLine(item.Value);
  25.             }
  26.  
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment