[英]Python Regex separating txt files into paragraphs
有沒有辦法使用正則表達式將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,但是如何決定只在正則表達式中查找換行符而不在空格中查找呢?
謝謝您的幫助。
不要使用正則表達式,只需使用split即可:
a="""1....
2....
3...."""
print map(lambda x:x.strip(),a.split("\n"))
注意:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.