fork download
  1. import re
  2. from string import punctuation
  3. my_text = "!where??and!!or$$then:)"
  4. pattern = "[" + punctuation.replace('\\','\\\\').replace(']', r'\]') + "]+"
  5. print(re.sub(pattern, r' \g<0> ', my_text).strip())
  6.  
Success #stdin #stdout 0.03s 9556KB
stdin
Standard input is empty
stdout
! where ?? and !! or $$ then :)