【发布时间】:2017-10-05 00:01:04
【问题描述】:
我的问题是通过 Python 中的正则表达式从文件中提取某个段落(例如,通常是中间段落)。
示例文件如下:
poem = """The time will come
when, with elation,
you will greet yourself arriving
at your own door, in your own mirror,
and each will smile at the other's welcome,
and say, sit here. Eat.
You will love again the stranger who was your self.
Give wine. Give bread. Give back your heart
to itself, to the stranger who has loved you
all your life, whom you ignored
for another, who knows you by heart.
Take down the love letters from the bookshelf,
the photographs, the desperate notes,
peel your own image from the mirror.
Sit. Feast on your life."""
如何在python中使用正则表达式提取这首诗的第二段(意思是“你一生……书架”)?
【问题讨论】:
-
只需捕获
\n\n之间的任何内容。 -
我现在正与第二段的模式作斗争。需要帮助!
-
@BurhanKhalid 你能给我提供具体的代码来捕获两个 \n\n 之间的任何东西吗?非常感谢
标签: python regex extract paragraph