正则表达式选择以字符开头的连续行

问题描述 投票:0回答:1

我有如下文字:

 *   Some text in a bullet list.
 * Some more text in the same bullet list

Break my pattern with a random number of normal text.
That keeps going for some time

 * Back to some text in a bullet list
 * That goes on

我想制作一个正则表达式,能够提取项目符号列表中的所有连续行。 例如,在我之前的示例中,我想选择以下内容:

Group 1
 *   Some text in a bullet list.
 * Some more text in the same bullet list

Group 2
 * Back to some text in a bullet list
 * That goes on`

我尝试了多个正则表达式,但无法将提取限制为连续列表。 例如,此正则表达式

re.findall(r"\* +(.*+)", text)
将所有项目符号列表返回为单个组(但不要按连续的项目符号行进行拆分)

regex
1个回答
0
投票
(^(?:\s*\* \N+\n)+)

如果您将上面的正则表达式与 re.compile 和 re.MULTILINE (python) 一起使用,它就可以工作。

在这里您可以看到实际效果:https://regex101.com/r/iJzUcz/1

© www.soinside.com 2019 - 2024. All rights reserved.