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

noreply@sourceforge.net noreply@sourceforge.net
Fri, 29 Nov 2002 13:18:28 -0800


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

Category: Regular Expressions
Group: None
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


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

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