如何使用javascript从url字符串中提取url文件扩展名 [英] How to pull url file extension out of url string using javascript
本文介绍了如何使用javascript从url字符串中提取url文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 javascript 查找 URL 的文件扩展名?示例网址:
How do I find the file extension of a URL using javascript? example URL:
http://www.adobe.com/products/flashplayer/include/marquee/design.swf?width=792&height=294
我只想要整个 URL 的swf".如果 url 也是以下格式,我需要它来查找扩展名
I just want the 'swf' of the entire URL. I need it to find the extension if the url was also in the following format
http://www.adobe.com/products/flashplayer/include/marquee/design.swf
显然这个网址后面没有参数.
Obviously this URL does not have the parameters behind it.
有人知道吗?
提前致谢
推荐答案
function get_url_extension( url ) {
return url.split(/[#?]/)[0].split('.').pop().trim();
}
示例:
get_url_extension('https://example.com/folder/file.jpg');
get_url_extension('https://example.com/fold.er/fil.e.jpg?param.eter#hash=12.345');
输出 ------> jpg
outputs ------> jpg
这篇关于如何使用javascript从url字符串中提取url文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文