Advertisement
Krissy

ExtractEmails

Jan 27th, 2013
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class ExtractEmails
  8. {
  9.     static void Main()
  10.     {
  11.         string input = @"Please contact us by phone (+359 222 222 222) or
  12.                        by email at exa_mple@abv.bg or at baj.ivan@yahoo.co.uk.
  13.                        This is not email: test@test. This also: @telerik.com. Neither this: a@a.b.";
  14.         string[] splitted = input.Split(' ');
  15.  
  16.         for (int i = 0; i < splitted.Length; i++)
  17.         {
  18.             if (Regex.IsMatch(splitted[i], @"[\w.]{2,20}@[\w]{2,20}[.]{1}[\w.]{2,6}"))
  19.             {
  20.                 Console.WriteLine("{0} is a valid email", splitted[i]);
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement