3 ms·
What is the issue with regex?
by pdenya 15y ago
What is the issue with regex?
- eropple 15y agohttp://ex-parrot.com/~pdw/Mail-RFC822-Address.html http://ex-parrot.com/~pdw/Mail-RFC822-Address.html Okay, that's a little bit flip. Regexes are fine when used in well-understood cases when they're properly documented for whatever guy comes after you and has to deal with them. The "now you have two problems" part, IMO, comes more from the way most people use them instead of any particular flaw in regexes themselves.
- ominous_prime 15y agoA widely quoted aphorism, originally from a USENET post: "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems." —Jamie Zawinski, This as a re-purposed quote, originally referencing sed or awk, and numerous people since have substituted in XML.
- gaius 15y agoWhile regexps can look intimidating try this: write something that does a regexp using just "normal" language features. Greenspun's law applies equally here; any sufficiently complex parser will include a DSL for regular expressions...
- Retric 15y agoI think the root issue is deeper than that; regexps can't handle tree data structures of undefined depth. So while you can often get the common cases to work just fine, some of the edge case are often literally impossible to solve with regexps. PS: Parsing is one of those cases where you need to have the program do the types of things people are used to the source code doing. AKA, simply nesting if statements does not get you to a solution, which often leads to people tossing out lot's of buggy code. Creating a DSL (or Yet another LISP) can be really useful, but regexps is a dead end for a wide range of problems.
- getsat 15y agoRegex themselves are fine, but people try to do ridiculous things with them such as "parse" HTML. They're used when they shouldn't be, and they go unused when they should be used. :)