News for hackers. Stuff that matters.
Re:I don't know Regex by Qantourisc on Tuesday September 03, 2013 @02:51AM (#6319417)
Your email regex is wrong. There are some obscure email address that will not work. For example my.email [email protected]

For more see http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...

Re:I don't know Regex by joe_the_user on Tuesday September 03, 2013 @03:27AM (#6319525)
I think that actually says a lot about regexes as code.

The more corner cases you have to consider, the more unreadable the code gets, after a while by seemingly exponential degree.

And if you have a tool to build the regex, why not just use the tool's code as your source so the final result is readable.

Basically, pasting a big regex into your code hardly seems more desirable than pasting a bunch of assembler there. But assembler can unavoidable. This isn't.

Regex are cool as CS constructs though.

Re:I don't know Regex by cheald on Tuesday September 03, 2013 @05:37AM (#6319940)
Email addresses are specified by standard with a context-free grammar. While it may be possible to express certain CF grammars as regular grammars, you rapidly run into issues (such as optional bounding delimiter matching, or escaped delimiters) which are trivial to express with a stack, and frickin' hard to express without one. (This is, incidentally, the heart of the "don't try to parse XML with regexp" sentiment, because XML is (at least) a context-free grammar that cannot be properly expressed by a regular grammar)

If you are having severe problems with a regex, the issue might be that you need to use an actual parser rather than a simple pattern matcher.

Re:I don't know Regex by joe_the_user on Tuesday September 03, 2013 @08:30PM (#6324819)
At that rate, I can't see any good reason to use regexes for email ever.

If you know context-free language, recursive-descent parsers are fairly simple to write and maintain without any special tools.

Re:I don't know Regex by cheald on Tuesday September 03, 2013 @10:18PM (#6325188)
Well, if you want a spec-compliant email validator, then yeah, you probably want an actual parser. Most people are happy enough with a good-enough pattern match, though, which is substantially less code.
Re:I don't know Regex by zeckalpha on Tuesday September 03, 2013 @03:04AM (#6319452)
> validates an email adress (something you should never do with Regex, because you won't get it right, but anyway)

I think it is clear that this isn't the point.

Re:I don't know Regex by AdrianRossouw on Tuesday September 03, 2013 @02:59AM (#6319440)
apparently this is the correct fully rfc-compliant email validation regex:

http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html

Re:I don't know Regex by vacri on Tuesday September 03, 2013 @03:29AM (#6319531)
These guys say that a 430-character regex does the same trick as that 6k-character one (down in the RFC 2822 section)

http://www.regular-expressions.info/email.html

Re:I don't know Regex by btilly on Tuesday September 03, 2013 @03:19AM (#6319506)
Only if you do not add comments.

There was a fun proposal to avoid spam by adding comments inside your email address. Any true emailer should handle it. And regex should break.

Unfortunately Microsoft Exchange breaks. And that case is important enough that the idea never caught on.

Re:I don't know Regex by simpleigh on Tuesday September 03, 2013 @04:31AM (#6319751)
I might be wrong, but ISTR that no longer works 'cause RFC822 has been superseded (the new RFC extends the domain of valid addresses).

The term "works" is relative of course - I don't suppose anyone actually uses that regex!