Re: Emacs-style regex?

Adrian Phillips (tandem@freeze.oslo.dnmi.no)
19 Aug 1994 06:09:55 GMT

In article <9408181826.AA05896=guido@voorn.cwi.nl> Guido.van.Rossum@cwi.nl writes:

Newsgroups: comp.lang.python
Path: nntp-oslo.uninett.no!nac.no!eunet.no!nuug!EU.net!sun4nl!cwi.nl!python-list-request
From: Guido.van.Rossum@cwi.nl
X-Address: P.O. Box 94079, 1090 GB Amsterdam, The Netherlands
X-Organization: CWI (Centrum voor Wiskunde en Informatica)
Sender: Guido.van.Rossum@cwi.nl
Organization: CWI, Amsterdam
References: <3302nq$173@euas20.eua.ericsson.se>
Date: Thu, 18 Aug 1994 18:26:09 GMT
X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
Lines: 33

> Does python's regex module support the \n feature,
> where \n refers to the nth '\(\)' group?
>
> If so, what must I do to make the script below work?
>
> % cat regtest.py
>
> import sys, regex
>
> # This should match e.g. xxx___xxx:
> pat = regex.compile('\(xxx\)\(.*\)\1')
>
> if pat.search(sys.argv[1]) != -1:
> print pat.group(1), pat.group(2)
> else:
> print 'No match?'
>
> % python regtest.py 'xxx___xxx'
> No match?
>
> Mats Svensson

Hm... You should double the \ before \1, because otherwise it's
interpreted as an octal string escape. However after correcting I
can't get this to work either. The \1 is recognized alright, because
a simpler example (e.g. '\(xxx\)...\\1') works as expected, but the
feature you require doesn't work. It may be a bug in regexpr.c, the
copyleft-free reimplementation of Emacs regular expressions that I
use. I guess you'll have to live with it...

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
<URL:http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>

I suppose its possible for people to produce modules from copylefted
code that will be at the python sight but not be part of "python" as
such (new or to replace the with-python ones) - for example, the new
regex module being worked on by GNU is supposed all singing, all
dancing, but may well be copylefted.

Question is, can the current GNU regex module be plugged in instead of
the regexpr.c ?

In theory this question could apply to dbm, and maybe other modules
(which I'm not sure)

Adrian

--
-------------------------------------------------------------------------
= Adrian Phillips at            | BUT any thoughts in this are purely    =
= The Norwegian Meteorological  | my own and have nothing to do with     =
= Institute   	    	        | this establishment, thankfully.        =
= Net: adrian.phillips@dnmi.no  | Phone: 47 22 96 32 09 Fax: 47 22 96 30 50