Advertisement
yanass

Extract Emails Regex

Aug 2nd, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Extract_Emails
  7. {
  8.     class Program
  9.     {
  10.         static void Main()
  11.         {
  12.             string text = Console.ReadLine();
  13.             string pattern = @"[?!^ ][a-z0-9](?:[\/_\-?]+(?:\.[a-z0-9\/_-]+)*|(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(([0-5]|[0-4][0-9])|[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(([0-5]|[0-4][0-9])|[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])";
  14.  
  15.             MatchCollection emails = Regex.Matches(text, pattern);
  16.  
  17.             foreach(Match email in emails)
  18.             {
  19.                 string mail = email.Value.ToString().Trim();
  20.                 Console.WriteLine(mail);
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement