Re: Emacs-style regex?

Guido.van.Rossum@cwi.nl
Thu, 18 Aug 1994 20:26:09 +0200

> 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>