import re regex = r"(\w+-\w+)|-+"test_str = ("popcorn-flavoured---\n" "tic-tacs") result = re.sub(regex, r"\1", test_str)print (result)
Standard input is empty
popcorn-flavoured tic-tacs
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!