正则表达式:不包含特定文件类型
我正在搜索一个正则表达式,它可以命中所有不以 ".png"
或 ".jpg"
结尾的内容。我想找出不请求图像文件的 URL。
我发现了这样的东西: ([^\s]+(\.(?i)(jpg|png))$)
但这与我想要的几乎相反。
有没有简单的方法可以扭转这种情况?还是这个表达完全错误?!
提前致谢。 扬
I'm searching for a regular expression that hits everything that is NOT ending with ".png"
or ".jpg"
. I want to find out URLs that do not request an image file.
I found something like this: ([^\s]+(\.(?i)(jpg|png))$)
but this is pretty much the opposite of what I want.
Is there an easy way to reverse this? Or is this expression totally wrong?!
Thanx in advance.
Jan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以使用 负向预测 来完成:
([^\s]+ (\.(?i)(?!jpg$|png$)[^\s]+)$)
该表达式将匹配
file.gif
和file.png2
但不是file.png
。另请参阅:正则表达式帮助。 Lighttpd重写规则
This can be done using negative lookahead:
([^\s]+(\.(?i)(?!jpg$|png$)[^\s]+)$)
That expression will match
file.gif
andfile.png2
but notfile.png
.See also: Regex help. Lighttpd rewrite rule