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.'
>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)