[New-bugs-announce] [issue8122] re.sub doesn't handle properly matches with yes-pattern no-pattern

oliv report at bugs.python.org
Fri Mar 12 11:59:17 CET 2010


New submission from oliv <o_medoc at yahoo.fr>:

Using python 2.6.4 on Arch Linux

The regular expression syntax in python indicate: 

(?(id/name)yes-pattern|no-pattern)
Will try to match with yes-pattern  if the group with given id or name exists, and with no-pattern  if it doesn’t.

I used that functionnality but the code doesn't works anymore:
import re
myre = re.compile('(?P<port>[0-9]+/(tcp|udp))\s+(?P<status>\S+)\s+(?P<service>[a-zA-Z0-9_-]+)\s*(?P<details>.*)')
myre.sub('(?(<details>)\g<details>|\g<service>)',"443/tcp open  ssl      Microsoft IIS SSL")

> The output is:
'(?(<details>)Microsoft IIS SSL|ssl)'
Instead of:
Microsoft IIS SSL

It looks like a bug as it was working earlier...

----------
components: Build
messages: 100926
nosy: oliv
severity: normal
status: open
title: re.sub doesn't handle properly matches with yes-pattern no-pattern
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8122>
_______________________________________


More information about the New-bugs-announce mailing list