For school I\'m supposed to write a Python RE script that extracts IP addresses. The regular expression I\'m using seems to work with re.search() but not with <
findall returns a list of matches, and from the documentation:
If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group.
So, your previous expression had one group that matched 3 times in the string where the last match was 0.
To fix your problem use: exp = "(?:\d{1,3}\.){3}\d{1,3}"; by using the non-grouping version, there is no returned groups so the match is returned in both cases.