fork download
  1. import re
  2.  
  3. text = """
  4. Tumble Trouble Twwixt Two Towns!
  5. Was the Moon soon in the Sea
  6. Or soon in the sky?
  7. Nobody really knows YET.
  8. """
  9.  
  10. print(re.compile(r"((\w+)\2)(?=.*?\1)").sub('{\g<1>}', text.rstrip()))
Success #stdin #stdout 0.02s 9776KB
stdin
Standard input is empty
stdout
Tumble Trouble Twwixt Two Towns!
Was the M{oo}n soon in the Sea
Or soon in the sky?
Nobody really knows YET.