Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript js match-获取路径中的文件扩展名_Javascript_Regex_Match_Point - Fatal编程技术网

Javascript js match-获取路径中的文件扩展名

Javascript js match-获取路径中的文件扩展名,javascript,regex,match,point,Javascript,Regex,Match,Point,如何使用JavaScript获取路径中的文件扩展名 alert("http://max/fi.le.rar".match(/\..*/i)); 返回从第一个点开始的数据 .le.rar 但我只需要.rar试试这个: "http://max/fi.le.rar".match(/\.[^.]+$/); 试试这个: "http://max/fi.le.rar".match(/\.[^.]+$/); 我用子字符串做了一个测试,并从@WITHESS中分离出来。 50万次之后: .rar执行时间:4

如何使用JavaScript获取路径中的文件扩展名

alert("http://max/fi.le.rar".match(/\..*/i));
返回从第一个点开始的数据

.le.rar
但我只需要.rar

试试这个:

"http://max/fi.le.rar".match(/\.[^.]+$/);
试试这个:

"http://max/fi.le.rar".match(/\.[^.]+$/);
我用子字符串做了一个测试,并从@WITHESS中分离出来。
50万次之后:

.rar执行时间:47ms(sub)
rar执行时间:53ms(无点分割)
(经过更多测试后,执行时间大致相同)


我没有比赛经验

我用子字符串做了一个测试,并从@WITHESS中分离出来。
50万次之后:

.rar执行时间:47ms(sub)
rar执行时间:53ms(无点分割)
(经过更多测试后,执行时间大致相同)



我没有使用match的经验,或者您可以像这样使用javascript
split()
函数

var str="http://max/fi.le.rar";
var n=str.split(".");
alert(n[n.length - 1]);

或者您可以像这样使用javascript
split()
函数

var str="http://max/fi.le.rar";
var n=str.split(".");
alert(n[n.length - 1]);

我应该说明返回值是字符串数组我应该说明返回值是字符串数组