Description: regex to validate email address noteworthy: (1) It allows usernames with 1 or 2 alphanum characters, or 3+ chars can have -._ in the middle. username may NOT start/end with -._ or any other non alphanumeric character. (2) It allows heirarchical ... Matches: [[email protected]], [[email protected]], [[email protected]] [ More Details] Non-Matches: [[email protected]], [[email protected]], [[email protected]] 2. Expression: ^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Z a-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-z A-Z]{2,6}$
Description: The most complete email validation routine I could come up with. It verifies that: - Only letters, numbers and email acceptable symbols (+, _, -, .) are allowed - No two different symbols may follow each other - Cannot begin with a symbol - Ending domain ... Matches: [[email protected]], [[email protected]], [[email protected]] [ More Details] Non-Matches: [[email protected]], [[email protected]], [[email protected]] 3 Expression: ^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[ ^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA -Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01 -\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((? (?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a- zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angl e)>)$
email的:
w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+
更多:
http://www.mscenter.edu.cn/blog/yongsheng/archive/2004/11/19/308.aspx
string s_reg=@"^[a-zA-Z]{1}[a-zA-Z_0-9]*@[a-zA-Z\.0-9]+$";
提供点思路:首先用FileStream和StreamReader把文件读进一个string里。再通过正则表达式过滤。
System.IO.FileStream fs = new System.IO.FileStream(filePath,System.IO.FileMode.Open,System.IO.FileAccess.Read);
System.IO.StreamReader sr = new System.IO.StreamReader(fs);
string str = sr.ReadToEnd();
System.Text.RegularExpressions.Regex mailRegex = new System.Text.RegularExpressions.Regex(@"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");
System.Text.RegularExpressions.MatchCollection mc = mailRegex.Matches(str);
for(int i = 0; i<mc.Count; i++ )
Console.WriteLine( mc[i].ToString() );
前后加写其他东西,就读不出来了
虽然还有点问题,但是有了很大眉目
先把贴子结了吧
A-Z]\.)+[a-zA-Z]{2,9})$
Description: regex to validate email address noteworthy: (1) It allows usernames with 1 or 2 alphanum characters, or 3+ chars can have -._ in the middle. username may NOT start/end with -._ or any other non alphanumeric character. (2) It allows heirarchical ... Matches: [[email protected]], [[email protected]], [[email protected]] [ More Details] Non-Matches: [[email protected]], [[email protected]], [[email protected]] 2.
Expression: ^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Z
a-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-z
A-Z]{2,6}$
Description: The most complete email validation routine I could come up with. It verifies that: - Only letters, numbers and email acceptable symbols (+, _, -, .) are allowed - No two different symbols may follow each other - Cannot begin with a symbol - Ending domain ... Matches: [[email protected]], [[email protected]], [[email protected]] [ More Details] Non-Matches: [[email protected]], [[email protected]], [[email protected]] 3
Expression: ^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[
^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA
-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01
-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?
(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-
zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angl
e)>)$
Description: This accepts RFC 2822 email addresses in the form: [email protected] OR Blah <[email protected]> RFC 2822 email 'mailbox': mailbox = name-addr | addr-spec name-addr = [display-name] "<" addr-spec ">" addr-spec = local-pa ... Matches: [[email protected]], [Name Surname <[email protected]>], ["b. blah"@blah.co.nz] [ More Details] Non-Matches: [name [email protected]], [name."surname"@blah.com], [[email protected]]