如何不贪心多个回溯匹配 [英] How to non-greedy multiple lookbehind matches
问题描述
Source: <prefix><content1><suffix1><prefix><content2><suffix2>
Engine: PCRE
RegEx1: (?<=<prefix>)(.*)(?=<suffix1>)
RegEx2: (?<=<prefix>)(.*)(?=<suffix2>)
Result1: <content1>
Result2: <content1><suffix1><prefix><content2>
RegEx2所需的结果只是< content2>但这显然是贪婪的. 如何使RegEx2为非贪婪的,并仅使用最后一个匹配的Lookbehind?
The desired result for RegEx2 is just <content2> but it is obviously greedy. How do I make RegEx2 non-greedy and use only the last matching lookbehind?
[我希望我已经从NoteTab语法正确翻译了此内容.我不做 正则表达式编码. < prefix>,< content> & <后缀>术语仅表示任意字符串.只有<" ?< =" lookbehind命令中的有效.]
[I hope I have translated this correctly from the NoteTab syntax. I don't do much RegEx coding. The <prefix>, <content> & <suffix> terms are just meant to represent arbitrary strings. Only the "<" in the "?<=" lookbehind command is significant.]
我怀疑这很简单,但是经过太多小时的搜索, 放弃自己解决问题.
I suspect it is something simple but after too many hours of searching I'm giving up on solving it myself.
感谢您的帮助
艺术
推荐答案
我只是遇到了同样的问题.但就我而言,是
I just had the same problem. But in my case it was
(?<=<prefix>)(?:.(?!<prefix>))*(?=<suffix>)
那是我想要的.
此表达式将匹配<prefix>
和<suffix>
之间的字符串联的任何内容,并且不包含子字符串<prefix>
. (我想是的.我不太擅长regexp.)
This expression will match anything that is a concatenation of characters between <prefix>
and <suffix>
and doesn't contain the substring <prefix>
. (I think so. I'm not very good at regexp.)
这篇关于如何不贪心多个回溯匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!