有没有办法使用正则表达式将txt文件分成段落?
例如,如果这是我的文本文件:
They call for you: The general who became a slave; the slave who became a gladiator; the gladiator who defied an Emperor. Striking story.
Watch your thoughts, for they will become actions. Watch your actions, for they'll become...habits. Watch your habits for they will forge your character. Watch your character, for it will make your destiny.
我希望\ s在这里涉及但你如何决定只在正则表达式而不是空格中查找换行符?
感谢您的帮助。
答案 0 :(得分:1)
不要使用正则表达式,只需使用split:
a="""1....
2....
3...."""
print map(lambda x:x.strip(),a.split("\n"))
NB: