You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2010-11-26.20:31:54.710>created_at=<Date2010-11-25.16:39:12.326>labels= ['expert-regex', 'type-bug', 'invalid']
title='A bug related to matching the empty string'updated_at=<Date2010-11-26.20:31:54.708>user='https://bugs.python.org/lanyjie'
Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2).
When I do the following, I got an exception:
>>> re.findall('(d*)*', 'adb')
>>> re.findall('((d)*)*', 'adb')
When I do this, I am fine but the result is wrong:
>>> re.findall('((.d.)*)*', 'adb')
[('', 'adb'), ('', '')]
Why is it wrong?
The first mactch of groups:
('', 'adb')
indicates the outer group ((.d.)*) captured
the empty string, while the inner group (.d.)
captured 'adb', so the outer group must have
captured the empty string at the end of the
provided string 'adb'.
Once we have matched the final empty string '',
there should be no more matches, but we got
another match ('', '')!!!
So, findall matched the empty string in
the end of the string twice!!!
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: