Python 3 regex?

Mark Lawrence breamoreboy at
Tue Jan 13 06:34:31 CET 2015

On 13/01/2015 02:53, Rick Johnson wrote:
> On Monday, January 12, 2015 at 7:55:32 PM UTC-6, Mark Lawrence wrote:
>> On 12/01/2015 23:47, 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.
>> [snip]
>> If you wish to use a hydrogen bomb instead of a tooth pick
>> feel free, I won't lose any sleep over it.  Meanwhile I'll
>> get on with writing code, and for the simple jobs that can
>> be completed with string methods I'll carry on using them.
>> When that gets too complicated I'll reach for the regex
>> manual, knowing full well that there's enough data in
>> books and online to help even a novice such as myself get
>> over all the hurdles. If that isn't good enough then maybe
>> a full blown parser, such as the pile listed here [snip]
> Mark, if you're going to quote me, then at least quote me in
> a manner that does not confuse the content of my post. The
> snippet you posted was not a statement of mine, rather, it
> was a quote that i was responding to, and without any
> context of my response, what is the point of quoting
> anything at all? It would be better to quote nothing and
> just say @Rick, then to quote something which does not have
> any context.

You snipped the bit that says [normal cobblers snipped].

> Every python programmer worth his *SALT* should master the
> following three text processing capabilities of Python, and
> he should know how and when to apply them (for they all have
> strengths and weaknesses):
>      (1) String methods: Simplistic API, but with limited
>          capabilities -- but never underestimate the
>          possibilities!
>      (2) Regexps: Great for pattern matching with a powerful
>          and concise syntax, but highly cryptic and unintuitive
>          for the neophyte (and sometimes even the guru! *wink*).
>      (3) Parsers: Great for extracting deeper meaning from text,
>          but if pattern matching is all you need, then why not
>          use (1) or (2) -- are you scared or uninformed?

String methods, regexes, parsers, isn't that what I've already said 
above?  Why repeat it?

>      "We can easily forgive a child who is afraid of the
>      dark; the real tragedy of life is when men are afraid of
>      the light. -- Plato
> IMHO, if you seek to only match patterns, then string
> methods should be your first choice, however, if the pattern
> is too difficult for string methods, then graduate to
> regexps. If you need to extract deeper meaning from
> text, by all means utilize a parser.

I feel humbled that a great such as yourself is again repeating what 
I've already said.

> But above all, don't fall for these "religious teachings"
> about how regexps are too difficult for mortals -- that's
> just hysteria. If you follow the outline i provided above,
> you should find Python's "text processing Nirvana".

My favourite things in programming all go along the lines of DRY and 
KISS, with "Although practicality beats purity" being the most important 
of the lot.  So called "religious teachings" never enter into my way of 
doing things.  For example I can't stand code which jumps through hoops 
to avoid using GOTO, whereas nothing is cleaner than (say) GOTO ERROR. 
You'll (plural) find loads of them in cPython.

My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

More information about the Python-list mailing list