Tim Peters added the comment: This is how it's supposed to work: Python's re matches at the leftmost position possible, and _then_ matches the longest possible substring at that position. When a regexp _can_ match 0 characters, it will match starting at index 0. So, e.g.,
>>> re.search('(a*)', 'caaaat').span() (0, 0) shows that the regexp matches the empty slice 'caaaat'[0:0] (the leftmost position at which it _can_ match), and >>> re.search('(a(b+)a){0,1}', 'caabbaat').span() (0, 0) shows the same. The groups didn't match anything in this case, because the outer {0,1} said "it's OK if you can't match anything". Put another group around it: >>> re.search('((a(b+)a){0,1})', 'caabbaat').groups() ('', None, None) to see that the regexp as a whole did match the empty string. ---------- nosy: +tim_one _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17257> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com