所以我有一些句子,比如:
The window is over there. The lamp is on. The fire is burning.当我使用split('.')拆分它时然后用换行符连接它,它就失去了".“
然后我尝试了像(?<=\.)\s这样的正则表达式,但它在第二个和第三个字母的第一个字母之前产生了一个空格:
The window is over there.
The lamp is on.
The fire is burning.我不想要额外的空间。我想要:
The window is over there.
The lamp is on.
The fire is burning.谢谢
发布于 2013-01-14 04:50:01
".\n".join(i.strip() for i in a.split("."))发布于 2013-01-14 04:49:04
>>> test = "The window is over there. The lamp is on. The fire is burning."
>>> print test.replace(". ",".\n")
The window is over there.
The lamp is on.
The fire is burning.发布于 2013-01-14 04:50:03
显然没有处理特殊情况(即句点后没有空格),为什么不直接处理:
>>> s = 'The window is over there. The lamp is on. The fire is burning.'
>>> print s.replace('. ', '.\n')
The window is over there.
The lamp is on.
The fire is burning.https://stackoverflow.com/questions/14307949
复制相似问题