title: extract all email address from a text using c#
body: <p>Is there a way to extract all email addresses from a plain text using C# .</p>
  
  <p>For example </p>
  
  <blockquote>
    <p>my email address is mrrame@gmail.com and his email is mrgar@yahoo.com</p>
  </blockquote>
  
  <p>should return </p>
  
  <p>mrrame@gmail.com, mrgar@yahoo.com</p>
  
  <p>I have tried the following but it matches perfect emails only.</p>
  
  <pre><code> public const string MatchEmailPattern =
              @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
              + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
                + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
              + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
  
  
          public static bool IsEmail(string email)
          {
              if (email != null) return Regex.IsMatch(email, MatchEmailPattern);
              else return false;
          }
  </code></pre>