C# 从字符串获取电子邮件ID格式?

C# 从字符串获取电子邮件ID格式?,c#,C#,我有一个字符串,里面有很多电子邮件id 我想使用电子邮件格式从字符串中获取电子邮件id。 比如@之前的空格和@之后的空格 suppose i have string like this then how can i do this? "Yunnan Coffee with the scientific name-Coffee test@example.com Arabica L was the variation of Arabia Coffee." 那么我如何才能获得该电子邮件id?您可以

我有一个字符串,里面有很多电子邮件id

我想使用电子邮件格式从字符串中获取电子邮件id。 比如@之前的空格和@之后的空格

suppose i have string like this then how can i do this?

"Yunnan Coffee with the scientific name-Coffee test@example.com Arabica L was the variation of Arabia Coffee."
那么我如何才能获得该电子邮件id?

您可以使用以下方法:


谢谢,但是假设我有这样的绳子,我怎么能这样做呢?云南咖啡,学名咖啡test@example.comArabica L是Arabia Coffee的变体。“那么我如何才能获得该电子邮件id?您好,它为最后一个字符串工作,但不适用于此地址:云南省昆明市政教路14号650223.P.R.China
电子邮件:coopcoffee@163.net
福克斯:+86(871)-5195599
电话:+86(871)5122496
电话2:+86(871)5199410
“请告诉我它是如何工作的 string email = "test@example.com"; string[] tokens = email.Split('@'); string enailId = tokens[0]; string domain = tokens[1];
var regex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.Compiled);    
var s = "Yunnan Coffee with the scientific name-Coffee test@example.com Arabica L was the variation of Arabia Coffee.";
foreach (Match email in regex.Matches(s))
{
    Console.WriteLine(email.Value);
}