Which regex syntax mode?

Alex Martelli aleaxit at yahoo.com
Mon Sep 18 09:35:15 EDT 2000


"Tim Hammerquist" <tim at degree.ath.cx> wrote in message
news:slrn8s7u3b.li.tim at degree.ath.cx...
> Tim Peters <tim_one at email.msn.com> wrote:
> > > and was wondering with RegExp syntax mode was most like Perl's syntax?
> >
> > Probably the awk variant, but forget you asked that:  the "regex" module
has
> > been obsolete for years, and will probably go away someday.  Use the
"re"
> > module instead:  its syntax is a nearly exact clone of Perl5's regexp
> > syntax.  So you'll feel much more at home with that.
>
> Thank you.  I'm reading O'Reilly's Programming Python, based on Python
> 1.3, so it only mentions regex and regsub.  I'm glad I asked.  =)

FYI: I tried that book first, and it put me off Python for a year.

Fortunately, there was "Internet Programming with Python" around when
I came back to look at the language (due to the insistence of a colleague
to whom I now hold a great debt of gratitude...!-) -- that one is now
unfortunately out of print, but there are other good ones (I suggest
"Quick Python Book" for starters, and "Essential Python Reference", if
you can stand the too-tiny font, as a book of more durable reference
value).


> > You're in for a bit of culture shock, though.  There's nothing special
about
> > regular expressions in Python:  they're just another kind of object,
    [snip]
> I also come from C++, and welcome Python's true OO capabilities.  Regex
> are often overused, granted.  But when they're only only option, they're
> invaluable.

Yep, but nothing is lost in having them packaged as objects -- on the
contrary.  It enables you to write a function that will accept compiled
regular-expression objects *OR ANYTHING ELSE SOMEHOW IMPLEMENTING THE
.search METHOD IN A CALL-COMPATIBLE WAY*, e.g. using such objects to
"filter" incoming lines-of-text for acceptability/interest, and gain all
the benefits of polymorphism.  _Very_ handy...


Alex





More information about the Python-list mailing list