<posted & mailed> Stephen Boulet wrote: > How do I use the sub function to replace my match with my match > prepended by a newline? Simplest is to enlose your RE pattern in parentheses (making it a group) and then use a backreference \1 in the substitution: resulting_string = re.sub(r'(x.y.x)', r'\n\1', original_string) Alex