匹配所有网址,不包括jpg,gif,png [英] Match all URLs exclude jpg,gif,png
问题描述
我希望匹配所有网址但排除与该正则表达式相匹配的图片网址:jpe?g | gif | png。
I want to match all URLS but exclude image urls from beeing matched with that regex: jpe?g|gif|png .
\ b(?:https ?| FTP |文件):// [-A-Z0-9 +功放; @#/%=〜_ | $:?!;] * A-Z0-9 +功放; @#/%=〜 _ | $
\b(?:https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*A-Z0-9+&@#/%=~_|$
问题是带有排除的部分不是这样的:(?!jpe?g | gif | png)
The problem is that the part with the exclude is not working like this: (?!jpe?g|gif|png)
有没有人有解决方案呢?
Does anyone have a solution for it?
示例:
不是Matchen:
http://example.com/example.jpg
http://example.com/example231/example.gif
匹配:
http://example.com/example.html
http://example.com/example/?id=4331
http://example.com/example/example/ex_ample/ex-ample/?id=4331
推荐答案
只需使用(?!。*(?:\。jpe?g | \.gif | \.png)$)
启动正则表达式,
Just start your regex with (?!.*(?:\.jpe?g|\.gif|\.png)$)
,
所以如果你当前的正则表达式是 \ b(?:https?| ftp | file):// ...
,然后合并它到
so if your current regex is \b(?:https?|ftp|file)://...
, then merge it to
(?!。*(?:\。jpe?g | \.gif | \ .png)$)\\ \\ b(?:https?| ftp | file):// ...
同时阅读PHP URL验证
这篇关于匹配所有网址,不包括jpg,gif,png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!