小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

強(qiáng)悍的電子郵件地址(email address)正則表達(dá)式

 googo 2011-07-14

強(qiáng)悍的電子郵件地址(email address)正則表達(dá)式

原始來源: RegexLib.com
修改后加入了兩個(gè)新功能:
1,匹配類似 "lc <deerchao@xxx.com>" 這樣的包含姓名的格式.
2,添加了四個(gè)命名組: name, email, user, domain. 這樣可以方便取出相應(yīng)的信息.

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\-]+(?<!-)\.)+[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])+)\])(?'angle')(?(name)>)$", RegexOptions.Multiline | RegexOptions.ExplicitCapture);
MatchCollection mc 
= re.Matches(@"l c <abc@example.com>
Abc@example.com
aBC@example.com
abc.123@example.com
");
foreach (Match ma in mc)
{
  
}



原表達(dá)式的最大優(yōu)點(diǎn)就是匹配能力強(qiáng)大,能吃下各種符合規(guī)范(RFC2882)的表達(dá)式.
匹配WikiPedia上的10/11個(gè)合法郵件地址格式,不合法的一個(gè)也不匹配:

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) 評(píng)論(1) 編輯 收藏

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多