本文介绍了有效的电子邮件地址正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一些测试,但我想问问是否有人发现这个用于电子邮件验证的 ruby​​ 正则表达式有问题:

I have done some testing but I wanted to ask if anyone sees a problem with this ruby regular expression for email validation:

/A([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})/i

好看吗?

推荐答案

你已经很接近了,只需要再添加几个字符:

You were close, have to add just a few more characters:

(?:(?:
)?[ 	])*(?:(?:(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	]
)+||(?=[["()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:

)?[ 	])*)(?:.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(
?:
)?[ 	])+||(?=[["()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 
	]))*"(?:(?:
)?[ 	])*))*@(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-
31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*
](?:(?:
)?[ 	])*)(?:.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+
(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:
(?:
)?[ 	])*))*|(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+|
|(?=[["()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:
)
?[ 	])*)*<(?:(?:
)?[ 	])*(?:@(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
r
)?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[
 	])*)(?:.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)
?[ 	])+||(?=[["()<>@,;:\".[]]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*)(?:.(?:(?:
)
?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>
@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*))*(?:,@(?:(?:
)?[
 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,
;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*)(?:.(?:(?:
)?[ 	]
)*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\
".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*))*)*:(?:(?:
)?[ 	])*)?
(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\".
[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:
)?[ 	])*)(?:.(?:(?:

)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[[
"()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:
)?[ 	])
*))*@(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])
+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*)(?:
.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+|
|(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*))*>(?:(
?:
)?[ 	])*))*)?;s*)

不,我不是在开玩笑:http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

这篇关于有效的电子邮件地址正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:21