Python findall() for findall() and finditer() indicate that:
Empty matches are included in the result if they do not relate to the start of another match.
This can be demonstrated as follows:
In [20]: [m.span() for m in re.finditer('.*', 'test')] Out[20]: [(0, 4), (4, 4)]
Can someone tell me why this pattern returns an empty match in the first place? Shouldn't .* Consume the entire string and return a single match? And further, why at the end there is no empty match if I bind the template to the beginning of the line? eg.
In [22]: [m.span() for m in re.finditer('^.*', 'test')] Out[22]: [(0, 4)]
source share