这是一个奇怪的电子邮件正则表达式。电子邮件地址的正则表达式
我们可以有不同类型的电子邮件地址
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)
你可以试试各种组合...... 如果表达不适合任何地方,请告诉我。
我用过的一些假设:电子邮件地址(用户名)不会包含特殊字符,只能是文字或数字。
这是什么问题? – amit 2012-01-15 10:24:44
可能重复的[Python检查有效的电子邮件地址?](http://stackoverflow.com/questions/8022530/python-check-for-valid-email-address) – phihag 2012-01-15 10:24:59
@php我不认为这是一个骗局,实际上,我认为这甚至不是问题。 – amit 2012-01-15 10:25:57