News for hackers. Stuff that matters.
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.