Advertisement
Guest User

Untitled

a guest
Aug 4th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace ExtractEmails
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string input = Console.ReadLine();
  11. //string pattern = @"\b[A-Za-z][A-Za-z0-9\.\-_]+@[A-Za-z][A-Za-z\-]+[A-Za-z]\.[A-Za-z][A-Za-z]+";
  12. //string pattern = @"(?<=\s)[A-Za-z][A-Za-z0-9\.\-_]*@[A-Za-z][A-Za-z\-]+[A-Za-z]\.[A-Za-z][A-Za-z]+";
  13. //string pattern = @"(?<=\s)[A-Za-z0-9]+[\.\-]*[A-Za-z0-9]+@[A-Za-z]+[\.\-]*[A-Za-z]+\.[A-Za-z]{2,}";
  14. string pattern = @"(?<=\s)[A-Za-z0-9]+[\.\-_]*[A-Za-z0-9]+@[A-Za-z]+(?:[\.\-]*[A-Za-z]+)?\.[A-Za-z]{2,}";
  15.  
  16. MatchCollection emails = Regex.Matches(input, pattern);
  17.  
  18. foreach (Match email in emails)
  19. {
  20. Console.WriteLine(email.Value);
  21. }
  22. }
  23. }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement