钓鱼鱼在水下咬钩视频:强悍的电子邮件地址(email address)正则表达式
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 19:57:29
强悍的电子邮件地址(email address)正则表达式
原始来源: RegexLib.com修改后加入了两个新功能:
1,匹配类似 "lc
2,添加了四个命名组: name, email, user, domain. 这样可以方便取出相应的信息.
Regex re = new Regex(@"^((?'name'.+?)\s*<)?(?'email'(?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|""(?'user'(?=[\x01-\x7f])[^""\\]|\\[\x01-\x7f])*""\x20*)*(?'angle'<))?(?'user'(?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|""((?=[\x01-\x7f])[^""\\]|\\[\x01-\x7f])*"")@(?'domain'((?!-)[a-zA-Z\d\-]+(?)$", RegexOptions.Multiline | RegexOptions.ExplicitCapture);
MatchCollection mc = re.Matches(@"l c
Abc@example.com
aBC@example.com
abc.123@example.com
");
foreach (Match ma in mc)
{
}
原表达式的最大优点就是匹配能力强大,能吃下各种符合规范(RFC2882)的表达式.
匹配WikiPedia上的10/11个合法邮件地址格式,不合法的一个也不匹配:
Valid e-mail addresses
- abc@example.com
- Abc@example.com
- aBC@example.com
- abc.123@example.com
- 1234567890@example.com
- _______@example.com
- abc+mailbox/department=shipping@example.com
!#$%&'*+-/=?^_`.{|}~@example.com (all of these characters are allowed)- "abc@def"@example.com (anything goes inside quotation marks)
- "Fred Bloggs"@example.com
- "%()[]\;:,<>"@example.com
Invalid e-mail addresses
Abc.example.com (character @ is missing)Abc.@example.com (character dot(.) is last in local part)Abc..123@example.com (character dot(.) is double)A@b@c@example.com (only one @ is allowed outside quotations marks)%()[]\;:,<>@example.com (none of the characters before the @ is allowed outside quotation marks)
posted on 2008-06-14 15:24 deerchao 阅读(1718) 评论(1) 编辑 收藏
强悍的电子邮件地址(email address)正则表达式
身份证的正则表达式
正则表达式
谈一谈QTP中正则表达式的应用
匹配固话的正则表达式
常用HTML正则表达式
常用正则表达式
java正则表达式(2)
正则表达式 - RegexBuddy教程
常用正则表达式1
正则表达式Sed
常用正则表达式
正则表达式参考文档
Java正则表达式入门
JAVA正则表达式
Oracle正则表达式规则
深入浅出之正则表达式
apache的Jakarta-ORO库 的正则表达式的使用
关于正则表达式的贪婪与非贪婪模式
常用的JavaScript验证正则表达式 - JavaScript / Regular
只能输入正整数 已经常用的正则表达式
C#正则表达式整理备忘
正则表达式30分钟入门教程
ASP.NET 中的正则表达式