java - 正则表达式匹配 URL 中的文件扩展名
问题描述
我有以下带有测试用例的正则表达式regex101
.{0,}(\.jpg|\.gif).{0,}
我想在 URL 的末尾匹配包含 .gif 和 .jpg 扩展名的 URL。不幸的是,该域被命名为 gif.com。
这是我的测试用例:
1 - http://www.gif.com/test.jpg - should match
2 - http://www.gif.com/test.html - shouldn't match
3 - http://gif.com/test.jpg - should match
4 - http://gif.com/test.html - shouldn't match
我想将正则表达式更改为在案例 2 中不匹配。我尝试了一些负面的http://www后向查找,但我需要正则表达式来匹配整行。
解决方案
推荐阅读
- javascript - then方法中的代码不执行,进行错误处理
- arrays - 我相信我做了一个无限循环,但我不知道它是在哪里创建的
- python - 在模板中收到来自 Ajax 的发布请求后,Flask 无法重定向
- mysql - 数据库需要重复值作为主键(不允许使用哪个)?
- html - 如何将我的“记住我”复选框与中心对齐?
- hadoop - HBase wal 越来越大
- c++ - 限制第一人称相机的俯仰旋转c ++ ue4
- node.js - 除非节点版本不同,否则节点应用程序无法在端口 80 上启动
- reactjs - onChange 时 React Select 不触发
- assembly - 如何将结果总和值存储到内存 RISC-V