Python 3 regex?

Rick Johnson rantingrickjohnson at
Tue Jan 13 03:53:32 CET 2015

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.

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

    (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?

    "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.

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".

More information about the Python-list mailing list