3 ms·
I'm not absolutely sure this isn't a joke that got out-of-hand. This is the COBOL of regular expressions. :) Whilst the conventional regular expression syntax
by parenthephobia 10y ago
I'm not absolutely sure this isn't a joke that got out-of-hand. This is the COBOL of regular expressions. :)
Whilst the conventional regular expression syntax is arguably overly compact, this is just too far in the opposite direction!
Something more PEG-like, or even Perl 6 regex-like, would make more more readable regular expressions whilst not completely throwing out everything we think things mean. Hell, even /x -- ignore whitespace and comments -- can make things much clearer:
/ ^
[0-9a-z._%+-]+ # The local part. Mailbox/user name. Can't contain ~, amongst other valid characters.
\@
[0-9a-z.-]+ \. [a-z]{2,} # The domain name. We've decided a TLD can never contain a digit, apparently.
$ /x
Tangentally, there's no point validating email addresses with anything more complicated than /@/. If people want to enter an email address that doesn't work, they can and will. If you want to be sure that the address is valid, send it an email!
- ldiracdelta 10y agoSimilarly, python's re.VERBOSE can push up readability in combination with its named groups feature. https://docs.python.org/2/library/re.html#re.VERBOSE
- comboy 10y ago> Tangentally, there's no point validating email addresses with anything more complicated than /@/ Well once you have this in database, maybe you'll give it to some library, then maybe this poor little library will just paste it into the SMTP conversation. And maybe some user will be clever enough to exploit it. I believe that if you want to get X from the user, it's always a good idea to make super sure that it is actually X before passing it further. And I very much agree that whenever possible and necessary, simply splitting regular expression to multiple lines and using comments seems like a superior approach.
- Retra 10y agoThe point is not to parse email addresses with regex because an actual email parser is far more appropriate for the task.