我在控制台应用中有代码
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是空的你能告诉我什么问题我解决它大约一个小时
答案 0 :(得分:5)
试试这个
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
}
}
答案 1 :(得分:1)
如果我拿出/
& /i
。
[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?
或者,您也可以使用此...
/^[\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6}$/