3 ms·
Wow. /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'? ]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa| biz|com|coop|edu|gov|info|int|mil|muse
by palish 16y ago
Wow.
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?
]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|
biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|
pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.
[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
I mean... Why do this? Just, why? It's almost unreadable.
Just write a short 20-line function which validates an email address. Use if statements. Write comments. Then verify that your algorithm does in fact handle all corner cases, just like the regexp does. (Your verifications will be in the form of short, simple unit test case functions.)
To encourage regexp abuse like that is to encourage bad programming.
- Groxx 16y ago(late, but...) Frequently because Perl's regex library is insanely fast. Faster than if statements + smaller regex / roll-your-own. (as long as there's no look-ahead / look-behinds. It's still fast then, but custom functions can sometimes do better.)