Re: backreference in regexp
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: backreference in regexp

From: Fredrik Lundh <fredrik@pythonware.com>
Date: Tue Jan 31 2006 - 13:29:20 CET

Schüle Daniel wrote:

> Hello @all,
>
> >>> p = re.compile(r"(\d+) = \1 + 0")
> >>> p.search("123 = 123 + 0")
>
> 'search' returns None but I would expect it to
> find 123 in group(1)
>
> Am I using something that is not supported by Python
> RegExp engine or what is the problem with my regexp?

plus matches one or more instances of the previous item. to make
it match a plug sign, you have to escape it:

    p = re.compile(r"(\d+) = \1 \+ 0")

</F>
Received on Tue Feb 7 20:20:02 2006