import retext = "This is! ? a test! ?"print( re.sub(r"(?<=[^\w\s]|_)\s+(?=[^\w\s]|_)", "", text) )
Standard input is empty
This is!? a test!?
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!