我如何识别在点 '.' 之前有 space 的句子并删除这个 space
How can I identify sentences that have a space before a dot '.' and remove this space
给定一个随机文本,我如何识别在点“.”之前有一个 space 的句子,并删除这个 space?
my_text = 'The pressure is already being monitored. We will report the results soon . kind regards.'
预期结果(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.'
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)
k=[] # Take an empty list
for x in my_text.split('.'): # Split with all the '.'
if x==0: # For the First iteration do not add '.'
k.append(x.rstrip()) # rstrip() will remove any number of extra spaces
else:
k.append(x.rstrip()+'.') # Add '.' after each sentence.
''.join(k[:-1]) # Removing the last '.' since it will be inserted twice
给定一个随机文本,我如何识别在点“.”之前有一个 space 的句子,并删除这个 space?
my_text = 'The pressure is already being monitored. We will report the results soon . kind regards.'
预期结果(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.'
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)
k=[] # Take an empty list
for x in my_text.split('.'): # Split with all the '.'
if x==0: # For the First iteration do not add '.'
k.append(x.rstrip()) # rstrip() will remove any number of extra spaces
else:
k.append(x.rstrip()+'.') # Add '.' after each sentence.
''.join(k[:-1]) # Removing the last '.' since it will be inserted twice