Regular expression complexity or AbstractSingletonFactoryImplementationBeanStoredProcedure complexity?
Regular expression complexity or AbstractSingletonFactoryImplementationBeanStoredProcedure complexity?
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.
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.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.