[Linux] Regular expressions

Nick Seidenman nicks@argate.net
Thu, 12 Oct 2000 21:53:52 -0400 (EDT)


On Thu, 12 Oct 2000, Nick Simicich wrote:

> At 06:58 AM 10/12/2000 -0400, Nick Seidenman wrote:
> >On Thu, 12 Oct 2000, Tim Jones wrote:
> >
> >> Regular expressions are also useful in Python 
> >> (see the 're', 'regex', 'regsub' modules), 
> >
> >Since Tim brought it up, the re module supports both perl and emacs
> >regular expression semantics.
> 
> Huh?  I thought that re module was perl, the regex module was emacs.  Heck,
> you just mentioned this to me.

Quite right.  I mispoke.  You use regex (which is only kept for backward
compatibility) for emacs-style regular expression semantics and re for
newer/better (perl-style and then some) expressions.

> Is r"\x" new syntax as well?  I see that the regex doc goes around the
> world telling you when a backslash escapes something and when it doesn't so
> you know when you have to double and when not, while the re doc just tells
> you to use r"\x".

Those are raw strings, denoted by an 'r' prefixing a quoted string.  It's
sort of like 'L' appended to a numeric (integer) literal to denote a
python long integer.  It is not peculiar to the re module; it's another
form of python string literal and thus can be used anywhere.  I believe
these showed up right around the same time as the re module, so it's
probably two or three years old now.

----------------------------------------------------------------------
 Nick Seidenman, CISSP           |      "Ugly  programs are like ugly
 Senior Security Consultant      |  suspension bridges:  they're much
 Hyperon, Inc.                   |       more liable to collapse than
 www.hyperon.com                 |       pretty ones."  -Eric Raymond