s = '11xx22xx33xxBEGINxx44xx55xxENDxx66xx77' import rematches = re.findall('(?:^|xx)(BEGIN.*?END|.*?)(?=xx|$)', s)print matches
Standard input is empty
['11', '22', '33', 'BEGINxx44xx55xxEND', '66', '77']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!