按照下面的图,新的句子开头第一个字母大写。当结尾是“ ." , "!" , "?"的时候
re.sub('^\w|[.?!]\s*\w', lambda i: i.group().upper(), text)
def capitalize_beginning_of_sentences(text):
import re
txts = re.findall('[A-Z a-z]+[.?!]', text)
for i in range(len(txts)):
temp = txts[i].strip().split(' ')
temp[0] = temp[0].strip()
temp[0] = temp[0].capitalize()
txts[i] = ' '.join(temp)
print(txts)
return ' '.join(txts)
text = "hello class. good luck with the exam ! "
print(capitalize_beginning_of_sentences(text))