4 ms·
Both are awful. I have a particular disdain for regex abuse. I like to say that there are 3 stages in the use of regular expressions. 1) You don't get them a
by balloot 14y ago
Both are awful. I have a particular disdain for regex abuse. I like to say that there are 3 stages in the use of regular expressions.
1) You don't get them and think they're magical
2) You learn regular expressions, and find all kinds of places to apply your knowledge of greedy modifiers and positive lookbehinds.
3) You learn enough to realize that regular expressions tend to be extremely brittle and try as hard as you can to avoid them.
There are a lot of very dangerous developers stuck in level 2.
- thespin 14y agoI use them constantly but almost always BRE. And I'm still discovering new tricks using only BRE. I guess I'm too dumb to use anything more clever. I'll never be a Larry Wall. I still feel I have more to learn just on the level of BRE. I still think there are more hidden gems. A lot of developers seem to have a serious disdain for anything that might be construed as the "lowest common denominator". I don't get it. Somehow I find a tremendous versatility in the LCD. It works in so many environments. I can rely on it to work, no matter what the size of the input. But then, if you go buy a book on RE, what do you get? An explanantion of the most ridiculously complex and difficult to maintain RE. As if the author is just showing off. Mastery of the basics is too boring I guess. Too simple.
- colomon 14y agoRegular expressions are just like everything in programming. Used properly they are a huge boon. Used improperly, they're a disaster. Here's a practical example. I spent half a day coding this algorithm (ASCII string in STEP format to an array of Unicode code points) in 70 lines of C++ without regular expression. It took me 15 minutes to recode it in Perl 6 using regular expressions: while $step.chars > 0 { given $step { when /^ '\\S\\' (.)/ { @unicode.push(ISO8859toUnicode($page, 128 | $0.ord )); } when /^ '\\P' (.) '\\'/ { $page = $0.ord - 'A'.ord + 1; } when /^ '\\X' [ '2' | '4' ] '\\' (<hexdigits>+) '\\X0\\'/ { @unicode.push(:16($0)); } when /^ (.)/ { @unicode.push($0.ord); } } $step = $/.postmatch; } This (admittedly completely untested) version is drastically shorter and much less brittle.