Python 3在句子末尾插入空格正则表达式替换

时间:2018-05-15 09:46:36

标签: regex python-3.x text-mining

我有一些像这个例句

的文本
s = 'The cat sat on the mat.The dog sat on the log.'

我想在完全停止之前插入一个空白区域。 我试过了

whitespace_after_full_stop_regex = '[a-z]\.[A-Z]'
s = re.sub(whitespace_after_full_stop_regex, '. ', s)

但是这给了我。

'The cat sat on the ma he dog sat on the log.'

如何在我想要保留的角色之间“插入”空格?

0 个答案:

没有答案