[英]Regex split the string at \n but skip the first one if it is \n\n
[英]How to convert a string to a list, split by the string '\n\n\n\n\n'?
我有一个带有文本的字符串,其中包含\\ n。 喜欢:
"Information moreinformation moreinformation \n\n\n\n\n Information moreinformation moreinformation \n\n\n\n\n Information moreinformation moreinformation"
现在我想要一个列表,由\\ n \\ n \\ n \\ n \\ n字符串拆分。 所以我想:
['Information moreinformation moreinformation', 'Information moreinformation moreinformation', 'Information moreinformation moreinformation']
我已经尝试过了,但这不起作用。 然后我还有一个字符串。
with open ("file.txt", "r") as file:
content = file.readlines()
content = ' '.join(content)
content.split('\n\n\n\n\n')
print (content)
content = content.split('\n\n\n\n\n')
尝试这个。 但是,您没有更改内容变量的数据类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.