I need to find the first occurrence of a string between two substrings in a large string in python, and I'm getting some unexpected behavior. Here's an example:
import re
str = 'STUFF start STUFF I CARE ABOUT end STUFF end STUFF end'
regex = re.compile('start.*end',re.DOTALL)
stufficareabout = regex.search(str)
print(stufficareabout.group())
I'm expecting to get 'start STUFF I CARE ABOUT end' as a result, but I'm instead getting 'STUFF start STUFF I CARE ABOUT end STUFF end STUFF end'. I thought regex.search returns the first match it finds, which to me would mean it would stop after the first "end" match, not keep going until the last one.