Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用正则表达式c从文本中提取电子邮件地址#_C#_Regex - Fatal编程技术网

C# 使用正则表达式c从文本中提取电子邮件地址#

C# 使用正则表达式c从文本中提取电子邮件地址#,c#,regex,C#,Regex,我在控制台应用程序中有代码 reg = new Regex(@"/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i"); string text = "wjeqklejqwek myEmail@hotmail.com a;lekqlwe anothermail@mail.ru"; parseTextByTagName("", text); MatchCollection coll = reg.Matches(tex

我在控制台应用程序中有代码

reg = new Regex(@"/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i");
  string text = "wjeqklejqwek myEmail@hotmail.com a;lekqlwe anothermail@mail.ru";
  parseTextByTagName("", text);
  MatchCollection coll =   reg.Matches(text);
}
当我调试它时,它显示coll是空的。你能告诉我什么问题我正在解决它大约一个小时吗

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
  }
}
试试这个

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
  }
}

如果我取出
/
&
/I
,您的正则表达式对我有效

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

或者,您也可以使用此


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

如果我取出
/
&
/I
,你的正则表达式对我有效

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

或者,您也可以使用此


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

it wokred!!!!问题出在哪里?谢谢你的代码,这是100%的工作,这个正则表达式不适用于电子邮件地址中的dot,例如a。b@c.com不行。要修复此问题,请改用“[A-Za-z0-9\-\+\.]+@[A-Za-z0-9\-]+\.([A-Za-z]{2,3})(?:\.[A-z]{2}”)”它太棒了!!!!问题出在哪里?谢谢你的代码,这是100%的工作,这个正则表达式不适用于电子邮件地址中的dot,例如a。b@c.com不行。若要修复此问题,请改用“[A-Za-z0-9\-\+\.]+@[A-Za-z0-9\-]+\.([A-Za-z]{2,3})(?:\.[A-z]{2}”)“您知道正则表达式几乎不能覆盖所有有效的电子邮件地址吗?例如,这是一个有效的电子邮件地址-
“非常不寻常.@.un寻常.com”@example.com
,%&+*^_{}}~@example.org
您确实知道正则表达式不能覆盖所有有效的电子邮件地址吗?例如,这是一个有效的电子邮件地址-
“very.unspecial.@.unspecial.com”@example.com
-这也是-
!$%&'*+-/=^_{}| ~@example.org