PyWart: Python regular expression syntax is not intuitive.
steve+comp.lang.python at pearwood.info
Wed Jan 25 20:54:54 EST 2012
On Wed, 25 Jan 2012 09:16:01 -0800, Rick Johnson wrote:
> In particular i find the "extension notation" syntax to be woefully
> inadequate. You should be able to infer the action of the extension
> syntax intuitively, simply from looking at its signature. I find myself
> continually needing to consult the docs because of the lacking or
> misleading style of the current syntax. Consider:
The only intuitive interface is the nipple. Everything else is learned.
Nevertheless, there are legitimate problems with Python's regex syntax.
It is based on Perl's syntax, and even Larry Wall agrees that it has some
Read Apocalypse 5: Wall gives a fantastic explanation of what's wrong
with current regex syntax (without such trivial platitudes as "it is not
intuitive", as if we can all agree on what it intuitive), why it has
become that way, and what Perl 6 will do about it.
Regexes are essentially a programming language. They may or may not be
Turing complete, depending on the implementation (true regexes are not,
but Perl regexes are more powerful than true regexes), but they are still
a programming language. And users want regexes to be concise, otherwise
they would ask for richer string search methods and avoid regexes
The problem is that conciseness and readability are usually (but not
always) in opposition. So regexes will never be as readable as Python
code, because the requirements of regexes -- that they be short, concise,
and usually written as one-liners (or at least one-liners must be
possible) -- do not meet Python standards of readability. How can they?
Regexes are shorthand. If you want longhand, write your search in
> PS: In my eyes, Python 3000 is already a dinosaur.
We look forward to seeing your re-write. I'm sure all right-thinking
programmers will flock to your Python fork as soon as you start writing
More information about the Python-list