News for hackers. Stuff that matters.
Re:Perfect email regex finally found by JadeNB on Friday May 28, 2010 @05:37PM (#1387741)
> Regex is the only real sensible way to validate strings until something better is found.

There are plenty of ‘better’ (in the sense of ‘more powerful’) string-validation techniques. For example, lots of grammars are expressed in BNF; the languages that can be so expressed are (if I remember my Chomsky hierarchy correctly) the context-free grammars, a strictly larger class than the regular languages. The extra power comes from the fact that they have the expressive power of a finite-state automaton augmented by an (infinite) stack. (It's fair to argue that it's not ‘really’ infinite, since a computer's memory is finite; but, in that sense, real-life computers will never be Turing complete.)

(Of course, common ‘regular-expression’ libraries aren't actually regular any more, because of added features like capture groups. I don't know if they recognise all CFG's, though; I suspect not.)

Given this, why would we use regular expressions? Well, by intentionally sacrificing power, we can achieve faster matching (http://swtch.com/~rsc/regexp/regexp1.html) and, probably, lower memory usage. Sometimes this trade-off is worth it, even if it means that the match must be somewhat fuzzy; but sometimes one needs a precise match, and regexes just aren't up to the job.

Re:Perfect email regex finally found by huherto on Friday May 28, 2010 @06:33PM (#1387864)
> Given this, why would we use regular expressions? If I can get a way with a simple regexp I will use it. If it starts getting complicated I would use something else.(e.g. top down parser or a combination)
Re:Perfect email regex finally found by JadeNB on Friday May 28, 2010 @07:24PM (#1387954)
> If I can get a way with a simple regexp I will use it. If it starts getting complicated I would use something else.(e.g. top down parser or a combination)

Isn't that what I said?

Re:Perfect email regex finally found by huherto on Thursday June 03, 2010 @11:54AM (#1401648)
(If understood correctly) You based it in speed and memory efficiency. I rather base it on having something simple and readable.