使用负向后查找的正则表达式在Notepad ++中不起作用 [英] Regular expression using negative lookbehind not working in Notepad++

查看:187
本文介绍了使用负向后查找的正则表达式在Notepad ++中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源文件,实际上有数百个字符串flecha.jpgflecha1.jpg出现,但是我需要查找任何其他.jpg图像(例如casa.jpgmoto.jpg等)出现

我尝试使用带有负向后看的正则表达式,如下所示:

(?<!flecha|flecha1).jpg

但是它不起作用! Notepad ++只是说这是一个无效的正则表达式.

我已经在其他地方尝试过正则表达式,并且可以正常工作,这里是一个示例,所以我想这是一个问题NPP处理正则表达式或使用lookbehinds/lookaheads语法.

那么我如何在NPP中获得相同的正则表达式结果?

如果有用,我正在使用Notepad ++ 6.3版Unicode

另外,如果您是如此友善,实现相同功能但使用可选数字(在这种情况下仅为'1')作为我的字符串后缀的语法是什么? (即使它在NPP中不起作用,也要知道)...

我尝试了(?<!flecha[1]?).jpg,但是它不起作用.它应该与其他正则表达式相同,请参见此处( RegExr )

解决方案

Notepad ++似乎没有实现可变长度的后备浏览(某些工具会发生这种情况).一种解决方法是使用多个固定长度的后向查找:

(?<!flecha)(?<!flecha1)\.jpg

您可以检查,匹配项相同.但这适用于npp.

注意,由于您尝试匹配扩展名,因此我逃避了.,因此您想要的是文字..您使用的方式是通配符-可以是任何字符.

不幸的是,关于额外的问题,由于我们不能具有可变长度的后缀,因此如果没有多个后缀,就不可能有可选的后缀(数字).

I have a source file with literally hundreds of occurrences of strings flecha.jpg and flecha1.jpg, but I need to find occurrences of any other .jpg image (i.e. casa.jpg, moto.jpg, whatever)

I have tried using a regular expression with negative lookbehind, like this:

(?<!flecha|flecha1).jpg

but it doesn't work! Notepad++ simply says that it is an invalid regular expression.

I have tried the regex elsewhere and it works, here is an example so I guess it is a problem with NPP's handling of regexes or with the syntax of lookbehinds/lookaheads.

So how could I achieve the same regex result in NPP?

If useful, I am using Notepad++ version 6.3 Unicode

As an extra, if you are so kind, what would be the syntax to achieve the same thing but with optional numbers (in this case only '1') as a suffix of my string? (even if it doesn't work in NPP, just to know)...

I tried (?<!flecha[1]?).jpg but it doesn't work. It should work the same as the other regex, see here (RegExr)

解决方案

Notepad++ seems to not have implemented variable-length look-behinds (this happens with some tools). A workaround is to use more than one fixed-length look-behind:

(?<!flecha)(?<!flecha1)\.jpg

As you can check, the matches are the same. But this works with npp.

Notice I escaped the ., since you are trying to match extensions, what you want is the literal .. The way you had, it was a wildcard - could be any character.

About the extra question, unfortunately, as we can't have variable-length look-behinds, it is not possible to have optional suffixes (numbers) without having multiple look-behinds.

这篇关于使用负向后查找的正则表达式在Notepad ++中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆