I am using the following code:
CARRIS_REGEX=r'<th>(\d+)</th><th>([\s\w\.\-]+)</th><th>(\d+:\d+)</th><th>(\d+m)</th>'
pattern = re.compile(CARRIS_REGEX, re.UNICODE)
matches = pattern.finditer(mailbody)
findall = pattern.findall(mailbody)
But finditer and findall are finding different things. Findall indeed finds all the matches in the given string. But finditer only finds the first one, returning an iterator with only one element.
How can I make finditer and findall behave the same way?
Thanks
Best Answer
I can't reproduce this here. Have tried it with both Python 2.7 and 3.1.
One difference between
finditer
andfindall
is that the former returns regex match objects whereas the other returns a tuple of the matched capturing groups (or the entire match if there are no capturing groups).So
prints
If you want the same output from
finditer
as you're getting fromfindall
, you need