2012-01-15 42 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

相关问题