search :
checks compliance anywhere in the string (this is what Perl does by default).
re.search(r'(ab*)', 'aaAaABBbbb', re.I)
This will try to match a (ignored case) followed by zero or more b . He will find a match in the first a , since he is followed by zero b , and he returned it.
re.search(r'(ab.*)', 'aaAaABBbbb', re.I)
This will try to match a , then b , and then with anything ( .* Is greedy). It matches ABBbbb because it is the first sequence that matches the regular expression.
re.search(r'(ab+)', 'aaAaABBbbb', re.I)
Finally, this will correspond to a followed by at least one b (again, the case is ignored). This is the first ABBbbb match and it is returning.
source share