正则表达式 – 一种多线,多变贪婪,正则表达
发布时间:2020-12-14 06:02:08 所属栏目:百科 来源:网络整理
导读:鉴于以下文本,您将使用什么PCRE正则表达式来提取以粗体标记的部分? 00:20314 lorem ipsum want this kryptonite 00:02314 quux padding dont want this00:03124 foo neither this 00:01324 foo but we want this stalagmite 00:02134 tralala not this 00:0
鉴于以下文本,您将使用什么PCRE正则表达式来提取以粗体标记的部分?
00:20314 lorem ipsum want this kryptonite 00:02314 quux padding dont want this 00:03124 foo neither this 00:01324 foo but we want this stalagmite 00:02134 tralala not this 00:03124 bar foo and we want this kryptonite but not this(!) 00:02134 foo bar and not this either 00:01234 dolor sit amet EOF IOW,我们想用正则表达式提取以“^ 0”开头并以“(kryptonite | stalagmite)”结尾的部分. 一直在咀嚼这一点,发现它很难破解. TIA! 解决方法
一种方法是将
Negative Lookahead与内联(?sm)
dotall and multi-line modifiers结合使用.
(?sm)^0(?:(?!^0).)*?(?:kryptonite|stalagmite) Live Demo (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |