有没有婚配url但除了图片之外的正则表达式

WBOY
Release: 2016-06-13 11:20:03
Original
770 people have browsed it

有没有匹配url但除了图片之外的正则表达式?
例如http://www.abc.com/和http://www.abc.com/images/index.php都能匹配,
但http://www.abc.com/images/logo.gif就不能匹配。
我写的表达式会匹配到http://www.abc.com/images/logo.这段

(http\://)?([a-z0-9_-]+\.)+(com|net|cn|org){1}(\/[a-z0-9_-]+)*\.?(?!jpg|jpeg|gif|png|bmp)
Copy after login


------解决方案--------------------
刚才没有测试环境,随意写的,想想有点问题,找了个环境重新写了一个

$s='http://www.abc.com/image/index.php"http://www.abc.com/images/logo.gif"';
preg_match_all('#/[^/]*(?------解决方案--------------------
gif))"#', $s, $m); // -6
var_export($m);

大致吧,你自己理解一下再修改来用
这里\....匹配圆点和三字符的扩展名,没有圆点扩展名或者不是三个字符的情况自己摸索吧
------解决方案--------------------
(?i)(?:https?
------解决方案--------------------
ftp)://[-a-z\d.]+/?(?!/)([-a-z\d+&@#%=~_
------解决方案--------------------
!:,.;]+/)*(?#去掉图片的URl)(?![-a-z\d+&@#%=~_!,.;].*?\.(?:jpg
------解决方案--------------------
jpeg
------解决方案--------------------
gif
------解决方案--------------------
png
------解决方案--------------------
bmp))[-a-z\d+&@#%=~_!,.;]*(?:\?[a-z\d+&@#/%=~_
------解决方案--------------------
!:,.;]*)?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!