fork(3) download
  1. import re
  2.  
  3. sentences = [""""'This has punctuation, and it's hard to remove. ?" """,
  4. "Did you see Cress' haircut?.",
  5. "This 'thing' hasn't a really bad habit, you know?.",
  6. "'I bought this for $30 from Best Buy it's. What a waste of money! The ear gels are 'comfortable at first, but what's after an hour."]
  7.  
  8. for s in sentences:
  9. # Remove the specified characters
  10. new_s = re.sub(r"""["?,$!]|'(?!(?<! ')[ts])""", "", s)
  11.  
  12. # Deal with the final dot
  13. new_s = re.sub(r"\.", " .", new_s)
  14. print(new_s)
  15.  
Success #stdin #stdout 0.1s 10096KB
stdin
Standard input is empty
stdout
This has punctuation and it's hard to remove .  
Did you see Cress haircut .
This thing hasn't a really bad habit you know .
I bought this for 30 from Best Buy it's . What a waste of money The ear gels are comfortable at first but what's after an hour .