例如给出字符串:
Reading my book... hate it... The childs is good read. This is funny.
它应该返回:
Reading my book... hate it... The childs is good read . This is funny .
请注意d
和.
之间的空格。
答案 0 :(得分:0)
使用negative lookaround assertion,您可以过滤不遵循点(.
)且后面没有点((?<!\.)
)的(?!\.)
:
>>> text = 'Reading my book... hate it... The childs is good read. This is funny.'
>>> import re
>>> re.sub(r'(?<!\.)\.(?!\.)', r' .', text) # Replace the matched dot with ` .`
'Reading my book... hate it... The childs is good read . This is funny .'