Live data from Hacker News

Perfect email regex finally found

fightingforalostcause.net

51–60 of 118 posts

Re: Perfect email regex finally found

#51
post #27

It's certainly more concise than my previous favorite, qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]' dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]' atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' + '\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+' quoted_pair = '\\x5c[\\x00-\\x7f]' domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d" quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22" domain_ref = atom sub_domain = "(?:#…

This is the same one I've been using the last couple of years, and I wish I could remember where I first came across it.

Re: Perfect email regex finally found

#52
I have an implementation of RFC3696 http://www.faqs.org/rfcs/rfc3696.html (which is the spec for validating emails) in Python here - http://www.acooke.org/lepl/api/lepl.apps.rfc3696-module.html

That is part of Lepl - http://www.acooke.org/lepl/ - and although it's implemented in a recursive decent parser, much is compiled to regular expressions for efficiency. So you get the best of all worlds: regexp efficiency; parser accuracy; standards based.

A blog post on the compilation to regexps is here - http://www.acooke.org/cute/LEPLOptimi0.html

Re: Perfect email regex finally found

#53
Then they DDoS the login form with a long password and email, and between the md5 and the retarded regex, your cpu is choking. You still need to limit action by ip and add some kind of a captcha system. People can just invite themselves to gmail a million times. Email verification is not so useful anymore.

Re: Perfect email regex finally found

#56
post #28

Earlier quoted context omitted.

Along those lines, I've settled on the following overly permissive regex: /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/ -- it makes sure it looks something like an email address (a@b.cd)

What if I want to receive mail directly at my TLD?

Interestingly, there is a test for that in the article - under the "These should be invalid" section.

Re: Perfect email regex finally found

#57
post #11

Nothing is finished, nothing is permanent, and nothing is perfect. In particular, one of the evaluation tests used here is wrong: it requires failure-to-match on a TLD with a digit in it: numbersInTLD@domain.c0m In fact, IDN TLDs will have digits in them. An internet-draft is in the works to replace RFC1123's IDN-unfriendly implication that digits in TLDs are illegal: http://tools.ietf.org/html/draft-liman-tld-names-…

If you say "will have" and "in the works" means it isn't the standard and the current test is valid.

Re: Perfect email regex finally found

#58
post #3
post #2

How ugly do non-regex based email validation functions look? I've never seen one, but I've always wondered if that was a more elegant solution.

Regex is the only real sensible way to validate strings until something better is found. Even if you just wrote code to do it manually, you'd really just be writing a verbose and poorly implemented finite state machine that globbed symbols together, which in the end, would just be inferior to writing a well tested Regex string. Regex can be easier to read if you have something do a graphical expansion for you. Otherw…

If I remember correctly my theory of languages course a parser (implemented in a turing machine) is more powerful than a reggex (which is a finite state machine).

Re: Perfect email regex finally found

#59
post #46
post #3

Earlier quoted context omitted.

Regex is the only real sensible way to validate strings until something better is found. Even if you just wrote code to do it manually, you'd really just be writing a verbose and poorly implemented finite state machine that globbed symbols together, which in the end, would just be inferior to writing a well tested Regex string. Regex can be easier to read if you have something do a graphical expansion for you. Otherw…

> Regex is the only real sensible way to validate strings until something better is found. There are plenty of ‘better’ (in the sense of ‘more powerful’) string-validation techniques. For example, lots of grammars are expressed in BNF; the languages that can be so expressed are (if I remember my Chomsky hierarchy correctly) the context-free grammars, a strictly larger class than the regular languages. The extra power…

> Given this, why would we use regular expressions? If I can get a way with a simple regexp I will use it. If it starts getting complicated I would use something else.(e.g. top down parser or a combination)

Re: Perfect email regex finally found

#60
post #28

Earlier quoted context omitted.

Along those lines, I've settled on the following overly permissive regex: /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/ -- it makes sure it looks something like an email address (a@b.cd)

What if I want to receive mail directly at my TLD?

interestingly i count 19 TLD's with mx records. but judging from your earlier post you know as well as i do (i use @w.tf for many purposes) that there are pretty much no web forms on the planet that would take such an address. tis a shame, but such addresses while pretty nifty are also frequently unusable. not to mention trying to explain to someone that that is really your email address and if it doesn't work they should talk to their ISP/mail client author/etc...well, suffice it to say they won't be getting in touch with you that way anyhow. (be that a blessing or curse, it's just reality)
Post reply on HN