+ Reply to Thread
Results 1 to 2 of 2

Thread: Extract Email Accounts from text

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    19

    Extract Email Accounts from text

    I have a lot of texts that has E-Mails and i'd like to have a function that extract the E-Mail accounts from text.
    Last edited by philip; 11-08-2012 at 11:24 PM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    10
    So here is the code i created :
    Code:
            static void Main(string[] args)
            {
                string text = "Hi my name is philip and my email address is : philip@yahoo.com , my cousin email is : cousin-philip@yahoo.com and my phone number is 555-555-5555";
    
                ExtractEmails(text);
            }
    
            static void ExtractEmails(string str)
            {
                string RegexPattern = @"\b[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}\b";
    
                // Find matches
                System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(str, RegexPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                
                string[] MatchList = new string[matches.Count];
    
                // add each match
                int c = 0;
                foreach (System.Text.RegularExpressions.Match match in matches)
                {
                    MatchList[c] = match.ToString();
                    c++;
                }
                
    			// Display the Results
                for (int i = 0; i < MatchList.Length; i++)
                {
                    Console.WriteLine(MatchList[i].ToString());
                }
            }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts