3 ms·
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
by cheald 13y ago
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.
- joe_the_user 13y agoAt 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.
- cheald 13y agoWell, 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.