import re
res = re.findall(r'^foo (\S+(?:\s+\S+)*) (\S+) baz (\d+)', 'foo hello hello hello baz 33')
print(res)