Php 匹配直到空格数字组合
我的目标是从任何空格+数字++空格(包括)匹配到下一个空格(不包括)。例如:Php 匹配直到空格数字组合,php,regex,regex-greedy,Php,Regex,Regex Greedy,我的目标是从任何空格+数字++空格(包括)匹配到下一个空格(不包括)。例如: 1) this is an example 2) yet another example 1) with embedded pattern 2) another embedded pattern 3) still another 4) final 结果: 1) this is an example 2) yet another example 1) with embedded pattern 2) another
1) this is an example 2) yet another example 1) with embedded pattern 2) another embedded pattern 3) still another 4) final
结果:
1) this is an example
2) yet another example 1) with embedded pattern 2) another embedded pattern
3) still another
4) final
提供的答案是可以的
(?:(?!\s\d+\)).)+
但是如果我在模式中嵌入了类似的模式,如何避免呢?
更新
唯一的比较或条件是主枚举将增加,而不是减少:1)2)3)4)5)依此类推。但是,嵌入的枚举总是从1)再次开始,因此基本上,如果嵌入的枚举小于或等于主枚举,则我们将跳过它。试试这个:
(\d+\) [A-Za-z+ ]+)
请参见演示:为什么要在每行末尾包含
[^,因为有时我会在每行末尾添加