nginx中的regex前瞻问题

nginx中的regex前瞻问题,regex,nginx,negative-lookbehind,Regex,Nginx,Negative Lookbehind,我有如下URL列表: iphone-repair/iphone-4s-repair/iphone-4s-lcd-repair iphone-repair/iphone-4s-repair/iphone-4s-glass-repair iphone-repair/iphone-4s-repair/iphone-4s-glass-amp-lcd-replacement iphone-repair/iphone-4s-repair/iphone-4s-screen-repair rewrite ^

我有如下URL列表:

iphone-repair/iphone-4s-repair/iphone-4s-lcd-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-amp-lcd-replacement
iphone-repair/iphone-4s-repair/iphone-4s-screen-repair
rewrite ^(.*?)-(glass|glass-.*?lcd|lcd)-.*?(replacement|repair)(.*?)  https://${server_name}$1-screen-repair$5 last;
iphone-repair/iphone-4s-repair/iphone-4s-front-glass-amp-lcd-amp-back-glass-replacement
我想这样重写它们:

iphone-repair/iphone-4s-repair/iphone-4s-lcd-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-amp-lcd-replacement
iphone-repair/iphone-4s-repair/iphone-4s-screen-repair
rewrite ^(.*?)-(glass|glass-.*?lcd|lcd)-.*?(replacement|repair)(.*?)  https://${server_name}$1-screen-repair$5 last;
iphone-repair/iphone-4s-repair/iphone-4s-front-glass-amp-lcd-amp-back-glass-replacement
我让它像这样工作:

iphone-repair/iphone-4s-repair/iphone-4s-lcd-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-amp-lcd-replacement
iphone-repair/iphone-4s-repair/iphone-4s-screen-repair
rewrite ^(.*?)-(glass|glass-.*?lcd|lcd)-.*?(replacement|repair)(.*?)  https://${server_name}$1-screen-repair$5 last;
iphone-repair/iphone-4s-repair/iphone-4s-front-glass-amp-lcd-amp-back-glass-replacement
问题是也有类似的URL:

iphone-repair/iphone-4s-repair/iphone-4s-lcd-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-repair
iphone-repair/iphone-4s-repair/iphone-4s-glass-amp-lcd-replacement
iphone-repair/iphone-4s-repair/iphone-4s-screen-repair
rewrite ^(.*?)-(glass|glass-.*?lcd|lcd)-.*?(replacement|repair)(.*?)  https://${server_name}$1-screen-repair$5 last;
iphone-repair/iphone-4s-repair/iphone-4s-front-glass-amp-lcd-amp-back-glass-replacement
我们不希望发生任何重写

因此,我一直在用头敲击键盘,试图理解如果出现“front”一词,如何让lookback中止整个比赛

我试过这个

^(.*?)-(?<!front-)(glass|glass-.*?lcd|lcd)-.*?(replacement|repair)(.+)?
^(.*)-(?
但它似乎并没有中止整个比赛

非常感谢您的帮助!!

您可以试试这个

(?!.+-front)
反向前瞻,断言url不包含
front

^(?!.+-front)(.*?)-(glass|glass-.*?lcd|lcd)-.*?(replacement|repair)(.*?)


请查看链接上的说明。

非常感谢!!您能解释一下是什么让它起作用的吗?是什么让嵌套捕获组解决了这个问题?还有,为什么您要使用负向前看而不是向后看
(?!.+-front)
是一个否定的先行词,检查前面是否有一个单词。我使用否定的先行词,因为它们支持量词,但否定的先行词不支持。