Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. namespace _01.Extract_Emails
  2. {
  3.  
  4.     using System;
  5.     using System.Text.RegularExpressions;
  6.  
  7.     public class RegexEx
  8.     {
  9.  
  10.         public static void Main()
  11.         {
  12.  
  13.  
  14.             string pettern = @"(\s|^)[a-z0-9]+([-._][a-z0-9]+)?@([a-z]+\-?[a-z]+\.)?([a-z]+\-?[a-z]+\.[a-z]+)";
  15.             //@"([a-z]+|[0-9]+)(\.[a-z]+|[0-9]+|[a-z]+|_[a-z]+|-[a-z]+)@[a-z]+(-[a-z]+\.[a-z]+|\.[a-z]+\.[a-z]+|\.[a-z]+)";
  16.             Regex regex = new Regex(pettern);
  17.  
  18.             string text = Console.ReadLine();
  19.  
  20.            // var text = ".Examples of valid users: stephan@abv.bg , mike03@abv.bg, s.johnson@abv.bg, st_steward@abv.bg, softuni-bulgaria@abv.bg, 12345@abv.bg.Examples of invalid users: --123@abv.bg, .....@abv.bg, nakov_ -@abv.bg, _steve @abv.bg, .info@abv.bg. < host > is a sequence of at least two words, separated by dots .Each word is sequence of letters and can have hyphens  between the letters.Examples of hosts: 123@softuni.bg, 123@software-university.com, 123@intoprogramming.info, 123@mail.softuni.org.Examples of invalid hosts: 123@helloworld, 123@.unknown.soft., 123@invalid-host-, 123@invalid - .Examples of valid emails: info@softuni-bulgaria.org, kiki@hotmail.co.uk, no-reply@github.com, s.peterson@mail.uu.net, info-bg@software-university.software.academy.Examples of invalid emails: --123@gmail.com, …@mail.bg, .info@info.info, _steve@yahoo.cn, mike@helloworld, mike@.unknown.soft., s.johnson@invalid-.";
  21.  
  22.             MatchCollection matches = regex.Matches(text);
  23.            
  24.  
  25.             foreach (Match email in matches)
  26.             {
  27.                
  28.                     Console.WriteLine(email.Value);
  29.                
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement