Making regex suck less

François Pinard pinard at iro.umontreal.ca
Sun Sep 1 20:45:58 EDT 2002


[Carl Banks]

> You might want to look at the Plex package.  [...]
>
> First, this will certainly be slower than regular expressions, since
> there are many Python calls needed to build the structure.  (Of course,
> after you've compiled it, it can be as fast as regexps.)

The Plex matching engine does not backtrack, which might be an advantage over
Python regexps at matching time, at least theoretically for some regexps.
Building the matching tables, however, consumes a lot of time.  So I guess
that for most usual regexps, Python regexps are quite OK.

> Second, even if you use re module, it is still nowhere near Perl-ish
> ugliness.  You still have Python's clean syntax outside of the pattern.

A clear and definite advantage! :-) :-)

> Third, readability is not a unilateral good thing; conciseness is also
> important [...]

Python regexps, given some flag at compilation time, may allow for embedded
whitespace and comments.  With proper care, difficult regexps could be made
less compact and more readable, without changing at all how they behave at
run-time.  Conciseness is a quality for short regexps.  Horrid regexps are
more advantageously written non-compactly.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list