如何使用JavaScript在路径中获取文件扩展名?因为第一点js匹配 - 在路径中获取文件扩展名
alert("http://max/fi.le.rar".match(/\..*/i));
返回数据
.le.rar
,但我只需要.rar程序
如何使用JavaScript在路径中获取文件扩展名?因为第一点js匹配 - 在路径中获取文件扩展名
alert("http://max/fi.le.rar".match(/\..*/i));
返回数据
.le.rar
,但我只需要.rar程序
试试这个:
"http://max/fi.le.rar".match(/\.[^.]+$/);
var path = "http://max/fi.le.rar";
var extention = path.substring(path.lastIndexOf("."), path.length);
我做了测试与子和分裂来自@智慧。
500000倍后:
.rar程序执行时间:47ms(分)
RAR执行时间:53ms(分裂无点)
(更后一些的测试的执行时间大约相同)
我有比赛没有经验
我需要使用匹配 –
,或者您可以使用JavaScript split()
功能这样
var str="http://max/fi.le.rar";
var n=str.split(".");
alert(n[n.length - 1]);
我需要使用匹配 –
我应该评论返回值是一个字符串数组 – Mahdi