You can use re.findall.
>>> text = 'start something something end start nothing nothing end'
>>> re.findall('start (.+?) end', text)
['something something', 'nothing nothing']
Return all non-overlapping matches of pattern in string, as a list of strings.
Pattern is
start followed by a space
- the
( indicates the start of the part (group) we're interested in
- the
. indicates arbitrary character
- the
+? indicates at least one, but as little as possible
- the
) indicates the end of the part (group) wer're interested in
- a space followed by
end.
The string is scanned left-to-right, and matches are returned in the order found.
If one or more groups are present in the pattern, return a list of
groups;
We're using groups, as shown above
this will be a list of tuples if the pattern has more than one
group.
We only use one group.
Empty matches are included in the result.