[Python-bugs-list] [ python-Bugs-645843 ] findall returns '' instead of None

noreply@sourceforge.net noreply@sourceforge.net
Sat, 30 Nov 2002 13:22:03 -0800


Bugs item #645843, was opened at 2002-11-29 16:18
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=645843&group_id=5470

Category: Regular Expressions
>Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Zooko O'Whielacronx (zooko)
Assigned to: Fredrik Lundh (effbot)
Summary: findall returns '' instead of None

Initial Comment:
Dear Pythonistas:

Thank you for Python!

>>> import re
>>> re.match("(B+)(A+)?", "B").groups() # test 1
('B', None)
>>> re.match("(B+)(A*)", "B").groups() # test 2
('B', '')
>>> re.findall("(B+)(A+)?", "B") # test 3
[('B', '')]
>>> re.findall("(B+)(A*)", "B") # test 4
[('B', '')]

I was expecting test 3 to return [('B', None)], so this
was a surprise to me.  I also think that this behavior
would be better, so that the results from test 3 and
test 4 can be distinguished.  (It doesn't matter in
this test, but it could if there is a '|' disjunction,
and I want to use "is None" to determine which side
matched.)

If you don't want to change the semantics, perhaps for
compatibility reasons, or because you prefer these
ones, then I suggest updating the doc of "findall" to
mention this behavior.

Regards,

Zooko


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-30 16:22

Message:
Logged In: YES 
user_id=80475

Yes, test #3 looks like a bug to me.
(A+) should not even be an empty match.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=645843&group_id=5470