def full_split(text, regex):
while text:<EOL><INDENT>m = regex.search(text)<EOL>if not m:<EOL><INDENT>yield text<EOL>break<EOL><DEDENT>left = text[:m.start()]<EOL>middle = text[m.start():m.end()]<EOL>right = text[m.end():]<EOL>if left:<EOL><INDENT>yield left<EOL><DEDENT>if middle:<EOL><INDENT>yield middle<EOL><DEDENT>text = right<EOL><DEDENT>
Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.

>>> list(full_split('word', re.compile('&.*?')))
['word']