fork download
  1. import re
  2.  
  3. regex = r"(\w+-\w+)|-+"
  4. test_str = ("popcorn-flavoured---\n"
  5. "tic-tacs")
  6.  
  7. result = re.sub(regex, r"\1", test_str)
  8. print (result)
Success #stdin #stdout 0.02s 9524KB
stdin
Standard input is empty
stdout
popcorn-flavoured
tic-tacs