TheBulgarianWolf

Email Extractor

Apr 18th, 2021
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace EmailExtractor
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Regex regex = new Regex(@"(^|(?<=\s))[A-Za-z\d]+([-._][A-Za-z\d]+)*@[A-Za-z]+(\-[A-Za-z]+)*(\.[A-Za-z]+)+");
  11.  
  12.             string text = Console.ReadLine();
  13.  
  14.             MatchCollection matches = regex.Matches(text);
  15.  
  16.  
  17.             Console.WriteLine("All emails are: ");
  18.             foreach(Match match in matches)
  19.             {
  20.                 Console.WriteLine(match);
  21.             }
  22.         }
  23.     }
  24. }
  25.  
Add Comment
Please, Sign In to add comment