Extract email adresses from text using RegEx c#

This question already has an answer here:

  • How to validate an email address using a regular expression? 74 answers

  • 尝试这个

    string strRegex = @"[A-Za-z0-9_-+]+@[A-Za-z0-9-]+.([A-Za-z]{2,3})(?:.[a-z]{2})?";
    Regex myRegex = new Regex(strRegex, RegexOptions.None);
    string strTargetString = @"wjeqklejqwek myEmail@hotmail.com a;lekqlwe anothermail@mail.ru";
    
    foreach (Match myMatch in myRegex.Matches(strTargetString))
    {
      if (myMatch.Success)
      {
        // Add your code here
      }
    }
    

    Your regular expression worked for me if I take out / & /i .

    [a-z0-9_-+]+@[a-z0-9-]+.([az]{2,3})(?:.[az]{2})?

    alternatively, you can also use this...

    /^[w-._+%]+@(?:[w-]+.)+[w]{2,6}$/

    链接地址: http://www.djcxy.com/p/16578.html

    上一篇: C#电子邮件地址验证

    下一篇: 使用RegEx c#从文本中提取电子邮件地址