Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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#_Regex - Fatal编程技术网

C# 用分号分隔的多个电子邮件目标的正则表达式

C# 用分号分隔的多个电子邮件目标的正则表达式,c#,regex,C#,Regex,我成功地为单个电子邮件执行正则表达式,如下所示: private readonly Regex _regex = new Regex(@"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"); 现在,我需要为多封电子邮件创建正则表达式,并用分号分隔 test@gmail.co

我成功地为单个电子邮件执行正则表达式,如下所示:

private readonly Regex _regex = new Regex(@"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                                          + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
现在,我需要为多封电子邮件创建正则表达式,并用分号分隔

test@gmail.com;test2@yahoo.com;test3@gmail.com
我发现这个正则表达式:

\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*
但是这个正则表达式也“接收”这个字符串的问题是:

h@kj.com;asds@gmail
我该怎么做


谢谢

我们不要为多个正则表达式构建正则表达式,因为这个正则表达式足够复杂,只需分别验证它们:

foreach (var email in emailList.Split(new char[] { ';' },
    StringSplitOptions.RemoveEmptyEntries))
{
    // validate email
}
此外,正则表达式并不完全适合这种情况,因为用户可以在分号之前或之后放置一个空格,多个空格,这会变得很凌乱,而且电子邮件已经够凌乱的了