FAQ
Greetings,

While writing some unit tests for a rfc1738 parser, I found the following
strange behaviour when using parenthesis in a named group regular
expression.

The following expression (?P<name>.*) and (?P<name>(.*)) don't behave in
the same way. When the matching fails, the first group will be None, but
the last one will contain an empty string.

The problem occurs with python 2.1.1 and 2.2. Python 1.5.2 OTH works fine.

I checked the documentation but didn't find any hint on this. So, before
submitting a bug report, I wanted to know if I missed something.


# Code exhibiting the problem
import sys
print sys.version

import re

# [ user [ : password ] @ ] host

x = re.compile("((?P(?P<host>.*)")
m = x.match("host")
print m.groupdict()

x = re.compile("((?P(?P<host>.*)")
m = x.match("host")
print m.groupdict()


# Outputs 1.5.2
1.5.2 (#1, Jul 5 2001, 03:02:19) [GCC 2.96 20000731 (Red Hat Linux 7.1 2
{'password': None, 'host': 'host', 'user': None}
{'password': None, 'host': 'host', 'user': None}

# Outputs 2.1.1
2.1.1 (#1, Sep 27 2001, 13:48:33)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)]
{'user': '', 'password':None, 'host': 'host'}
{'user': None, 'password': None, 'host': 'host'}

# Outputs 2.2
2.2 (#2, Jan 15 2002, 20:55:15)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-96)]
{'host': 'host', 'password': None, 'user': ''}
{'host': 'host', 'password': None, 'user': None}

Regards,
Pedro

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 30, '02 at 3:55p
activeJun 30, '02 at 3:55p
posts1
users1
websitepython.org

1 user in discussion

Pedro RODRIGUEZ: 1 post

People

Translate

site design / logo © 2022 Grokbase