Nov-10-2020, 06:53 PM
You could use catpuring groups
import re text = """ 23 24 10.00 to 11.00 - with a yellow overcoat with brown buttons and green rims. 25 26 12.00 to 13.00 - with short 27 shredded jeans with holes. 28 """ result = re.compile(r'(?P<A>\d+[.]\d+ to \d+[.]\d+ - \D+)\d+(?P<B>\D+)') matches = result.finditer(text) for match in matches: print(match.group('A') + match.group('B'))
Output:10.00 to 11.00 - with a
yellow overcoat with brown buttons
and green rims.
12.00 to 13.00 - with short
shredded jeans with holes.