You can use re.split()
, but you need to put parentheses around the template to keep the match:
>>> re.split('(ddd)', 'aaa bbb ccc ddd eee fff', 1) ['aaa bbb ccc ', 'ddd', ' eee fff']
but in this case you do not need a regex:
>>> 'aaa bbb ccc ddd eee fff'.partition('ddd') ('aaa bbb ccc ', 'ddd', ' eee fff')
Edit: I should probably also mention that with re.split you will get all the relevant groups, so you need to be prepared for this or use groups that don't contain a grab wherever you would otherwise use parentheses for priority:
>>> re.split('(d(d)d)', 'aaa bbb ccc ddd eee fff', 1) ['aaa bbb ccc ', 'ddd', 'd', ' eee fff']
Duncan
source share