2012-01-15 43 views
1

這是一個奇怪的電子郵件正則表達式。電子郵件地址的正則表達式

我們可以有不同類型的電子郵件地址

[email protected]

[email protected]

[email protected]

string1.string2的@ somemail.co.in

以下正則表達式可以找到上面的任何郵件

email2="[email protected]" 
email1="[email protected]'" 
email="[email protected]" 
email3="[email protected]" 
email4="[email protected]" 
email5="[email protected]" 
email6="[email protected]" 





re.search('\w+[.|\w]\[email protected]\w+[.]\w+[.|\w+]\w+',email) 

x=re.search('\w+[.|\w]\[email protected]\w+[.]\w+[.|\w+]\w+',email2) 
x.group() 
[email protected]' 
x=re.search('\w+[.|\w]\[email protected]\w+[.]\w+[.|\w+]\w+',email1) 
x.group() 
[email protected]' 
x=re.search('\w+[.|\w]\[email protected]\w+[.]\w+[.|\w+]\w+',email) 
x.group() 
'[email protected]' 

這似乎太複雜了吧...

我全身有點....

x=re.search('(\w+[.|\w])*@(\w+[.])*\w+',email4) 
x.group() 
'[email protected]' 

上述正則表達式現在可以檢測到任何類型的組合...

現在,如果您只希望電子郵件地址以'.in'或'.com'結尾 那麼您可以添加變體...

x=re.search('(\w+[.|\w])*@(\w+[.])*(com$|in$)',email) 

你可以試試各種組合...... 如果表達不適合任何地方,請告訴我。

我用過的一些假設:電子郵件地址(用戶名)不會包含特殊字符,只能是文字或數字。

+0

這是什麼問題? – amit 2012-01-15 10:24:44

+0

可能重複的[Python檢查有效的電子郵件地址?](http://stackoverflow.com/questions/8022530/python-check-for-valid-email-address) – phihag 2012-01-15 10:24:59

+0

@php我不認爲這是一個騙局,實際上,我認爲這甚至不是問題。 – amit 2012-01-15 10:25:57

回答

1
+0

我不知道這是否是重複的........我努力了.....認爲這是值得分享.. ......它不是一個問題......只是我認爲值得分享....... – 2012-01-16 09:37:22

+0

無論人們@堆棧溢出護理無視作爲肚子,Arindam的職位是EXTREEEEEEMELY中頻有用對我個人而言。再加上它有助於他們的搜索引擎只是在說... – 2017-03-04 04:02:23

相關問題