Python 3 regex?

Steven D'Aprano steve at pearwood.info
Tue Jan 13 07:39:44 CET 2015


On Mon, 12 Jan 2015 15:47:08 -0800, Rick Johnson wrote:

>> 'Some people, when confronted with a problem, think "I know, I'll use
>> regular expressions." Now they have two problems.' -  Jamie Zawinski.
> 
> I wonder if Jamie's conclusions are a result of careful study, or
> merely, an attempt to resolve his own cognitive dissonance? 

Zawinski is one of the pantheon of geek demi-gods, with Linus, Larry, 
Guido, RMS, and a few others. (Just don't ask me to rank them. I'm not 
qualified.) His comment isn't based on a failure to grok regular 
expressions, but on an understanding that many people use regular 
expressions inappropriately.

Here is more on the context of the famous quote:

http://regex.info/blog/2006-09-15/247


(By the way, the quote actually wasn't original to JZ, he stole it from 
an all but identical quote about awk.)


[...]
> For instance, in the following example, i contrive a similarly ironic
> statement to showcase the effects of such propaganda, but one that
> covers a subject matter in which laymen either: already understand, or,
> can easily attain "enough knowledge" to appreciate the humor.
> 
>     ############################################################ #      
>                     Ironic Twist                       #
>     ############################################################ # Some
>     diabetics, when confronted with hunger, think "I    # # know, I'll
>     eat a box of sugar cookies." -- now they have # # two problems!'    

Not the best of analogies, since there are two forms of diabetes. Those 
with Type 2 diabetes can best manage their illness by avoiding sugar 
cookies. Those with Type 1 should keep a box of sugar cookies (well, 
perhaps glucose lollies are more appropriate) on hand for emergencies.

http://www.betterhealth.vic.gov.au/bhcv2/bhcarticles.nsf/pages/Diabetes_explained?open

In any case, most people with diabetes (or at least those who are still 
alive) are reasonably good at managing their illness and wouldn't make 
the choice you suggest. You have missed the point that people who misuse 
regexes are common in programming circles, while diabetics who eat a box 
of sugar cookies instead of a meal are rare.

To take your analogy to an extreme:

  Some people, when faced with a problem, say "I know, I'll cut 
  my arm off with a pocketknife!" Now they have two problems.

This is not insightful or useful. Except in the most specialised and 
extreme circumstances, such as being trapped in the wilderness with a 
boulder on your arm, nobody would consider this to be good advice. But 
using regexes to validate email addresses or parse HTML? The internet is 
full of people who thought that was a good idea.


[...]
> Yes, i'll admit, regexps are very cryptic, but once you grasp their
> intricacies, you appreciate the succinctness of there syntax, because,
> what makes them so powerful is not only the extents of their pattern
> matching abilities, but their conciseness.

Even Larry Wall says that regexes are too concise and cryptic:

http://perl6.org/archive/doc/design/apo/A05.html



-- 
Steve



More information about the Python-list mailing list