匹配星号之间的多行

时间:2016-01-18 05:56:15

标签: regex

我正在以大纲格式记笔记,如下所示:

* Micro topic 1
** Microbes are small
** You can't see them!
*** Isn't that something?
* Micro topic 2
** I hope I like the teacher
*** She will be great!
** Micro is cool!

并想要一个匹配

的正则表达式
* Micro topic 1
** Microbes are small
** You can't see them!
*** Isn't that something?

* Micro topic 2
** I hope I like the teacher
*** She will be great!
** Micro is cool!

所以它会从一行*开始直到(不包括)以一行*开头的行匹配。

到目前为止:(?<!.)\*\s.+\n\*+.+\n\*+.+\n\*+.+

但我需要它是动态的。以单个*开头的每行之间的行数将不一致,并且它们之间的文本将不一致。

1 个答案:

答案 0 :(得分:1)

假设Python中使用正则表达式,如果您查找命名组b的结果,则以下内容应该有效。请注意,在Python中,?P<b>代表命名组b

(?P<b>\* ((?!\n\* ).)+)

您可以在https://regex101.com/r/jU1gX0/1

看到测试结果