Re:Email Regex that works 99.99%
by falcolas on Sunday February 22, 2015 @08:44AM
(#9089370)
After extensive research, I have finally come up with a way to improve upon 99.99%. I have come up with a regex which will work for 100% of email addresses, and a significant number of regex engines, as an added bonus! Behold:
/s
[ Parent
| on HN ]
$ nc localhost 25
220 uhura.z ESMTP
MAIL FROM:me
250 2.1.0 Ok
RCPT TO:root
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Look ma, no @!
.
250 2.0.0 Ok: queued as 8DB653E0065
quit
221 2.0.0 Bye/bow
.* it is!
Re:Email Regex that works 99.99%
by madaxe_again on Sunday February 22, 2015 @09:01AM
(#9089429)
Your verbosity is outlandish.
.*
will match all email addresses, and as an additional feature, all other strings too!
As we all know, more functionality with less code is better, therefore, this is clearly superior to all other regexes.
.+@.+
Should do the trickI considered that one, but I'm sure there's some system out there which doesn't require an account name ahead of the "@" symbol. We're shooting for 100% accuracy, after all. ;)
In that case, let me improve it further :-)
/@./
Though I'm not really sure there could be an email without username part.What regex would you suggest to match all e-mail addresses contained within an arbitrary body of text (as opposed to a single text field where you don't have worry about other text strings)?
The same one. If it has an '@' symbol embedded in it, it might be an email address. The only way to know for certain is to query the server its attached to.
Of course, if you're really trying to scrape email addresses reliably, looking for the '@' won't work reliably, since people are used to obfuscating their email with [at] or (at) to protect against spam (well, more spam). You will probably need to dive into AI theory to more reliably get email addresses.