Live data from Hacker News

Email Regex that works 99.99%

emailregex.com

51–60 of 65 posts

Re: Email Regex that works 99.99%

#51

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

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)?

Re: Email Regex that works 99.99%

#52
post #48

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

$ 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 . 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%

#53

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

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.

Re: Email Regex that works 99.99%

#54
Any idea on who is responsible for this micro-site?

I find it strange that there's no information on the author, sources, references, attribution, or credits on the page at all (other than the WordPress theme attribution).

Re: Email Regex that works 99.99%

#55
Nice idea. But a blind implementation of the grammar set out in the RFC is not performant. It's better to drop the obsolete syntax rules and folding white space. I have yet to see a user legitimately try to input an email with a comment mid-domain.

I implemented this in Ruby a while back, but I also went the next step and added a DNS check for a MX record. That way you can ensure there's a mail server to receive an email. Heck, I even wrote a blog post about it.

http://stevenkaras.github.io/blog/verifying-email-addresses

We've had pretty good feedback so far, but I've also spotted a few emails that people enter that are clearly fake (e.g. asdf at test.com).

Re: Email Regex that works 99.99%

#56
post #11

Alternatively, don't validate email addresses with a regex because it's pointless. Check that at least an '@' symbol is present and just send a damn email already[0]. Or better, don't send a damn email at all and let them access it because it's pointless to have an extra verification step. If you really want to do some clientside validation, just keep a basic regex and warn the user if the address doesn't seem right.…

Pointless? Methinks you've never worked with Mandrill or another service that penalizes you for hard/soft bounces.

If you validate emails as complying to the email format used by those services, you can reduce your hard bounces to a bare minimum. If you check for a valid mail server at that domain, you can reduce that to 0. If you connect to their server and check for an error for that mailbox, you can reduce your soft bounces to 0 too, but that requires a lot of legwork to set up.

Re: Email Regex that works 99.99%

#58
post #11

Alternatively, don't validate email addresses with a regex because it's pointless. Check that at least an '@' symbol is present and just send a damn email already[0]. Or better, don't send a damn email at all and let them access it because it's pointless to have an extra verification step. If you really want to do some clientside validation, just keep a basic regex and warn the user if the address doesn't seem right.…

Pointless? Methinks you've never worked with Mandrill or another service that penalizes you for hard/soft bounces. If you validate emails as complying to the email format used by those services, you can reduce your hard bounces to a bare minimum. If you check for a valid mail server at that domain, you can reduce that to 0. If you connect to their server and check for an error for that mailbox, you can reduce your so…

If you're willing to work with a service that you're paying for AND that penalizes you for erroneous bounces, that's kind of your problem.

Re: Email Regex that works 99.99%

#59
post #58

Earlier quoted context omitted.

Pointless? Methinks you've never worked with Mandrill or another service that penalizes you for hard/soft bounces. If you validate emails as complying to the email format used by those services, you can reduce your hard bounces to a bare minimum. If you check for a valid mail server at that domain, you can reduce that to 0. If you connect to their server and check for an error for that mailbox, you can reduce your so…

If you're willing to work with a service that you're paying for AND that penalizes you for erroneous bounces, that's kind of your problem.

It even sounds like you're doing their work.

Re: Email Regex that works 99.99%

#60
post #25

So in 1 million emails, there are 10,000 valid emails that will be rejected. I guess if you use this regex then you'd better hope your service doesn't become popular.

Your math is off by a factor of 100.

D'oh :-/ Really should have thought more before posting.
Post reply on HN