fork download
  1. import re
  2.  
  3. string = """
  4. this is is is is is is is is a string
  5. and here is another another another another example
  6. """
  7. rx = r'((\b\w+\b)\s*\2\s*)+'
  8.  
  9. string = re.sub(rx, r'\2 ', string)
  10. print string
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
this is a string
and here is another example