Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I identify sentences that have a space before a dot '.' and remove this space

Given a random text, how can I identify sentences that have a space before a dot ‘.’, and remove this space?

my_text = 'The pressure is already being monitored. We will report the results soon . kind regards.'

Expected result (We will report the results soon . => We will report the results soon.):

my_text = 'The pressure is already being monitored. We will report the results soon. kind regards.'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

import re

my_text = 'The pressure is already being monitored. We will report the results soon . kind regards.'

res = re.sub(r'\s+\.', r'.', my_text)
print(res)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading