与某些扩展名不匹配的正则表达式模式? [英] Regex pattern that does not match certain extensions?

查看:35
本文介绍了与某些扩展名不匹配的正则表达式模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个模式

^.*\.(?!jpg$|png$).+$

但是有一个问题——这个模式匹配 file.name.jpg(2 个点)

它在 filename.jpg 上正常工作(不匹配).我想弄清楚如何使它不匹配任何 .jpg 文件,即使文件名中有 2 个或更多点.我尝试使用后看,但 python 抱怨没有使用固定宽度(我不确定这意味着什么,但文件名将是可变长度.)

解决方案

这应该可行:^.*\.(?!jpg$|png$)[^.]+$>

I have this pattern written

^.*\.(?!jpg$|png$).+$

However there is a problem - this pattern matches file.name.jpg (2 dots)

It works correctly (does not match) on filename.jpg. I am trying to figure out how to make it not match ANY .jpg files even if the file's name has 2 or more dots in it. I tried using a look behind but python complains about not using a fixed width (which I'm not exactly sure what that means, but the file name will be variable length.)

解决方案

This should work: ^.*\.(?!jpg$|png$)[^.]+$

这篇关于与某些扩展名不匹配的正则表达式模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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