f*cking re module

Terry Hancock hancock at anansispaceworks.com
Wed Jul 6 02:30:33 EDT 2005


On Tuesday 05 July 2005 10:04 am, jwaixs wrote:
> The python re module is, in my opinion, a non beginner user friendly
> module. And it's not meant for beginning python programmers. I don't
> have any experience with perl or related script/programming languages
> like python. (I prefer to do things in c) So the re module is
> completely new for me.

I think you had an error of expectations here: Python provides
a regular expression module which is consistent with regular
expression syntax as it has come to be defined.  Your frustration
was entirely with regular expressions themselves, not the Python
implementation.  You would've had the same experience in Perl
or Ruby or for that matter, sed or awk.

In that vein, the Python documentation for the re module is only
that -- documentation for the module. It does not (and couldn't
reasonably be expected to) cover the subject of regular expressions
themselves.  You might as well expect the Python manual to
explain "object oriented programming", "data structures", 
"functional programming" or other semester-long computer
science subjects.  There are entire books dedicated to the
subject of learning regular expressions and pattern recognition
in general.

It's a fairly complex subject. After all, it's merely the simplest
one-dimensional case of a pattern recognition system, which
is essentially an AI discipline. Only the fact that the
one-dimensional case of discrete text is an extremely simple
case makes the subject tenable at all for ordinary programs.

If you're really interested in using this new technique, I would
suggest that you be prepared to be patient and tackle the
problem of learning it seriously, just as you did when you
learned to program in C in the first place.  And you might
want to read one of those aforementioned books, such as:

Mastering Regular Expressions (2nd ed)
by Jeffrey E. F. Friedl
http://www.oreilly.com/catalog/regex2/

And IMHO, Python actually makes regular expressions a lot
easier to handle than they are in some of the other languages
you could be attempting this in.  I've only tried regexes in
Python, Perl, and Javascript, but Python is definitely the one
I find easiest to cope with. ;-)

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list