fork download
  1. import re
  2.  
  3. text = "Hello, world. I'm a boy, you're a girl."
  4.  
  5. replaced = re.sub(
  6. '\S+', lambda m: re.match(r'^\W*(.*\w)\W*$', m.group()).group(1), text)
  7.  
  8. print(replaced)
  9.  
Success #stdin #stdout 0.02s 9936KB
stdin
Standard input is empty
stdout
Hello world I'm a boy you're a girl