If the template includes a capture group, this group will not be excluded:
>>> re.split(',', '1,2,3')
['1', '2', '3']
>>> re.split('(,)', '1,2,3')
['1', ',', '2', ',', '3']
>>> xs = re.split('(,)', '1,2,3')
>>> [part1+part2 for part1, part2 in zip(xs[1::2], xs[2::2])]
[',2', ',3']
devices = re.split('(mpath)', output)
for part1, part2 in zip(devices[1::2], devices[2::2]):
print part1 + part2
source
share