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
在行首断言位置^
匹配任何非空格字符:[^]
多次匹配任意字符*