News for hackers. Stuff that matters.
Re:Is it a must for every programmer to learn regular expres... by yen223 on Thursday August 16, 2012 @04:10AM (#4390379)
A typical regex looks like this:

  \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
Which is also what happens when a cat walks across the keyboard.
Re:Is it a must for every programmer to learn regular expres... by vorg on Thursday August 16, 2012 @04:50AM (#4390483)
There's nothing wrong with regex syntax. But there _is_ something wrong with the formatting of your example: it's not readable. Perhaps you _should_ write (assuming Java-syntax):

  (?x:              #standard token is an uppercase letter, digit, dot, or hyphen
    \b
    [A-Z0-9._%-]+   #1 or more of standard token, underscore, or percent sign
    @               #at-sign
    [A-Z0-9.-]+     #1 or more standard tokens
    \.              #dot
    [A-Z]{2,4}      #2 to 4 uppercase letters
    \b
  )
We can easily optimize for readability with regex syntax.
Re:Is it a must for every programmer to learn regular expres... by arethuza on Thursday August 16, 2012 @04:59AM (#4390507)
You can say that about pretty much anything if you aren't familiar with the syntax. That looks pretty readable to me - certainly far more portable and readable than equivalent code.

[It's also perfectly obvious that if this is an attempt to match email addresses that it's not a very good one - but I don't know the context where it's supposed to be used, it might be good enough for whatever the author intended].

Re:Is it a must for every programmer to learn regular expres... by Auguste on Thursday August 16, 2012 @04:45AM (#4390465)
I find that perfectly readable, except for the \b which I hadn't seen before. It's matching an all-uppercase email address.
Re:Is it a must for every programmer to learn regular expres... by subsystem on Thursday August 16, 2012 @04:50AM (#4390481)
There's plenty of upper case e-mail addresses that won't match that expression.
Re:Is it a must for every programmer to learn regular expres... by aidos on Thursday August 16, 2012 @05:08AM (#4390521)
Well, if you want to be fully compliant you can go for this 6kb monster

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

Re:Is it a must for every programmer to learn regular expres... by InclinedPlane on Thursday August 16, 2012 @04:52AM (#4390489)
/i
Re:Is it a must for every programmer to learn regular expres... by subsystem on Thursday August 16, 2012 @05:09AM (#4390523)
There's characters missing[1] and the tld is too short[2]. And even if that's fixed, we still don't match internationalized addresses or actually validate that the e-mail address exists. You're probably better off with something like...

   if "@" in email and "." in email.split("@")[1]:
       send_verification(email)
...but you should probably also check for common misspellings like "gmial.com" etc.

[1] http://en.wikipedia.org/wiki/Email_address#Syntax [2] http://en.wikipedia.org/wiki/List_of_Internet_top-level_doma...

Re:Is it a must for every programmer to learn regular expres... by Argorak on Thursday August 16, 2012 @04:17AM (#4390390)
Call me weird, but I find that very readable.