[英]How to match files end not with regex
I am trying to filter all files not ending with, for instance mp3
or wv
. 我正在尝试过滤所有不以
mp3
或wv
结尾的文件。
I have tried to use something like this ^.*(?<![mp3|wv])$
but this expression doesn't work. 我试图使用类似
^.*(?<![mp3|wv])$
但是此表达式不起作用。
Please help to create valid expression. 请帮助创建有效的表达式。
您可以改用负前瞻。
^(?!.*(?:mp3|wv)$).*
Since a lookbehind is a zero-width assertion, you can write: 由于后向是零宽度的断言,因此您可以编写:
^.*(?<!mp3)(?<!wv)$
or better ($ is a zero-width assertion too): 或更好($也是零宽度的断言):
^.*$(?<!mp3)(?<!wv)
if your regex flavor allows it (PCRE, Java), you can use an alternation: 如果您的正则表达式风格允许(PCRE,Java),则可以使用以下替代:
^.*$(?<!mp3|wv)
Note: if your goal is only to know if a string doesn't end with "vw" or "mp3", you can test if (?:mp3|wv)$
is false. 注意:如果您的目标只是知道字符串不是以“ vw”或“ mp3”结尾,则可以测试
(?:mp3|wv)$
是否为假。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.