Regular expressions

Steven D'Aprano steve at pearwood.info
Wed Nov 4 21:24:25 EST 2015


On Thu, 5 Nov 2015 11:24 am, rurpy at yahoo.com wrote:

> You will find they are an indispensable tool, not just in Python
> programming but in many aspects of computer use.

You will find them a useful tool, but not indispensable by any means.

Hint:

- How many languages make arithmetic a built-in part of the language? Almost
all of them. I don't know of any language that doesn't let you express
something like "1 + 1" using built-in functions or syntax. Arithmetic is
much closer to indispensable.

- How many languages make regular expressions a built-in part of the
language? Almost none of them. There's Perl, obviously, and its
predecessors sed and awk, and probably a few others, but most languages
relegate regular expressions to a library.

- How many useful programs can be written with regexes? Clearly there are
many. Some of them would even be quite difficult without regexes. (In
effect, you would have to invent your own pattern-matching code.)

- How many useful programs can be written without regexes? Clearly there are
also many. Every time you write a Python program and fail to import re,
you've written one.

Can you call yourself a well-rounded programmer without at least a basic
understanding of some regex library? Well, probably not. But that's part of
the problem with regexes. They have, to some degree, driven out potentially
better -- or at least differently bad -- pattern matching solutions, such
as (E)BNF grammars, SNOBOL pattern matching, or lowly globbing patterns. Or
even alternative idioms, like Hypercard's "chunking" idioms.

When all you have is a hammer, everything looks like a nail.





-- 
Steven




More information about the Python-list mailing list