Regex 正则表达式在句子后匹配多个patren

Regex 正则表达式在句子后匹配多个patren,regex,Regex,我想在重要部分中获得所有的名称,包括所有的非重要名称 我的文字: *** not important name 1 details name 2 details *** important name 3 details name 4 details name 3 name 4 我想要什么: *** not important name 1 details name 2 details *** important name 3 detai

我想在重要部分中获得所有的名称,包括所有的非重要名称

我的文字:

*** not important
name 1
    details
name 2
    details
*** important
name 3
    details
name 4
    details
name 3
name 4
我想要什么:

*** not important
name 1
    details
name 2
    details
*** important
name 3
    details
name 4
    details
name 3
name 4
我目前拥有的:

*** not important
name 1
    details
name 2
    details
*** important
name 3
    details
name 4
    details
name 3
name 4
这匹配所有的名字

(^[^ ].*$)
但当我试图只得到重要的东西时,它失败了

\*\*\* important[\s\S]*(^[^ ].*$)
还是这个

\*\*\* important[\s\S]*?(^[^ ].*$)
示例如下:

提前感谢您的帮助。

Code

或者:

(?:^\*{3} important$|\G(?!\A))[\s\S]*?\K^\S.*

结果 输入 输出
解释
  • (?:^\*{3}重要$|\G(?!\A))
    匹配以下任一项
    • ^\*{3}重要$
      匹配以下内容
      • ^
        在行首断言位置
      • \*{3}
        精确匹配
        *
        三次
      • 匹配文本空格字符
      • 重要
        按字面意思匹配
      • $
        在行尾断言位置
    • \G(?!\A)
      在上一次匹配结束时断言位置
  • [\s\s]*?
    匹配任意字符任意次数,但尽可能少
  • \K
    重置匹配的起点。任何以前使用的字符将不再包含在最终匹配中
  • ^
    在行首断言位置
  • [^]
    匹配任何非空格字符:
  • *
    多次匹配任意字符

✨✨ 魔术✨✨我花了一些时间来理解你们的解决方案,现在我学会了。谢谢!