将两个以上的点替换为 unicode 省略号

Replace more than two dots as unicode ellipsis

如何用 unicode 省略号替换字符串中的两个或多个句点?

例如

Hey. -> Hey. (does not change)
Hey.. -> Hey…  (all of  these change)
Hey... -> Hey…
Hey.... -> Hey…
Hey..... -> Hey…

这样就可以了。它使用正则表达式来匹配两个或多个点。

import re
s='Hey.....'
new_string = re.sub(r'[.][.][.]*', '…', s)
print(new_string)