1

For example: "This is some text . This is some text"

should be

"This is some text. This is some text"

We can use replase but replacing ' .' with '.', but it's not a good approach. Please let me know if you have any other idea which is generalised for any punctuation.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Try using regex. – George Jul 30 '21 at 14:03
  • 1
    Why your method wouldn't be a good method? I couldn't imagine an alternative situation where it would be not a good idea. – MSH Jul 30 '21 at 14:04
  • 1
    @MSH, It would be for dots only, but, as the title says, it might be other punctuation marks too. – George Jul 30 '21 at 14:05
  • Does this answer your question? [How to replace all occurrences of a string in JavaScript](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript) – UmAnusorn Aug 16 '21 at 08:17

1 Answers1

2

Sorry I'm on mobile but it would be something like this:

import re
print(re.sub(r'\s(?=[\.,:;])', "", yourstring))
Tranbi
  • 11,407
  • 6
  • 16
  • 33