fork download
  1. import re
  2. def repl(m):
  3. if m.group(1):
  4. return m.group(1).upper()
  5. else:
  6. return m.group()
  7.  
  8. s = "I want to remove all the punctuation, and then put it, back where it was."
  9. s = re.sub(r'([\w\s]+)|[^\w\s]+', repl, s)
  10. print(s)
Success #stdin #stdout 0.02s 9468KB
stdin
Standard input is empty
stdout
I WANT TO REMOVE ALL THE PUNCTUATION, AND THEN PUT IT, BACK WHERE IT WAS.