4 ms·
In the back of the Camel book there is an email matching regex. It takes the entire page. It probably doesn't handle some Unicode edge cases properly. Valida
by jandrese 10y ago
In the back of the Camel book there is an email matching regex. It takes the entire page. It probably doesn't handle some Unicode edge cases properly.
Validating emails with regexes is one of those things that seems like it should be fairly straightforward, but thanks to the language in the RFC it is actually a nightmare of rabbit holes filled with landmines.
- EvilTerran 10y agoThat would be the one shown here: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html I don't know about unicode, but I do note it says it doesn't handle comments (because, apparently, they can be nested - and perl's REs lack recursion).
- jandrese 10y ago> Implementing validation with regular expressions somewhat pushes the limits of what it is sensible to do with regular expressions (rest of the page is filled with line noise) LOL
- justinator 10y agoPerl has supported recursion in regex since around v5.10. The giant regex is not from the Camel book, but from O'Reilly's, Mastering Regular Expressions which does give the example in Perl, but was printed before v5.10 of Perl was released. (3rd ed. of Mastering Expressions was released in 2006; Perl v5.10 was released in 2006.). I believe the regex was published in the very first edition.
- EvilTerran 10y agoAh yes, sorry, it would have been more correct to say "perl's REs lacked recursion at the time ". I use PCRE pretty frequently, so knew that it's supported recursion for some time; but it's been a while since I've done anything non-trivial with perl itself, so couldn't remember if it too had that functionality or I was just getting their feature-sets confused. Evidently I guessed wrong - thanks for the correction.
- 77pt77 10y agoRFC 822 is the Internet's cancer. Really. Email addresses should have never been allowed to have comments. Since every new RFC maintains compatibility with this one, we'll probably be stuck with these poor choices for decades.
- Cyph0n 10y agoEmail addresses allow comments? Who the heck thought that was a smart idea!? I guess this is what you're referring to: James Doe <jdoe@a.com> The email - which is inside the <> - should be parsed correctly, while the rest should be treated as a "comment" [1]. [1]: https://www.cs.tut.fi/~jkorpela/rfc/822addr.html https://www.cs.tut.fi/~jkorpela/rfc/822addr.html
- 77pt77 10y agoNo No. Stuff like: * comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com. [1] * Also have a look at quotes [1]https://en.wikipedia.org/wiki/Email_address#Local-part https://en.wikipedia.org/wiki/Email_address#Local-part
- xiaoma 10y agoAnd the irony is that regular expressions, by definition, can't recurse. Nobody's gonna rename them to turing expressions, though.