Chris Uppal said:
I increasingly suspect that this is true of all, or nearly all, use of regexps.
I mean the cases where a regexp is hardwired (more-or-less) into the code;
they're undoubtedly valuable in applications where a user can enter a regexp to
control/configure something.
Certainly I can't think of any time that I've ever used them in "production"
(not throwaway) code, when I haven't eventually either removed them or
regretted that I couldn't. And just about every use of them I've read in this
newsgroup has been suspicious (either as a over-complicated tool for a simple
task, or a hacky approximation to a difficult task).
(BTW, as an old Unix hacker, with a particular fondness for awk and sed, I'm
happy to /use/ quite complicated regexps; it's just that I'm suspicious of
their ultimate value.)
Regex's offer a LOT of Bang for the Buck, but they are like any other good
abstraction -- implicitly limited in the long run. Since regex's aren't
extensible, they can only take the task so far before it runs out of
capability. Note, I'm not picking on regex's here; like I said, it works for
pretty much anything as you go to a higher level, they all have to
compromise something somewhere.
The real issue though is that regex's are considered a silver bullet, and
they also promote a style of development that is not easy to change when it
does break.
Since the regex is not only the grammar, but also the scanner, when you're
grammar fails, you lose the scanner as well. If you were writing your own
lexer/parser, they are much more robust and easier to change. If you find a
bug in your lexer/parser, you typically don't have to throw the entire thing
away to fix it. If you rely on regex's, it's very possible that you will run
into some wall that requires you to toss the entire thing out and start from
scratch.
Trvial case: Comma Seperated Values.
"1, 2, 3".split(",")
Ok.
Now, what about:
"1, \"This is a test, neet eh?\", 3" ?
Baby, bathwater, out the window.
All that said, I use them all the time as well in scripts. But pretty much
almost never in code.
Regards,
Will Hartung
(
[email protected])