How to get file extension in path using JavaScript?
alert("http://max/fi.le.rar".match(/\..*/i));
returns data since first dot
.le.rar
but I need only .rar
Try this:
"http://max/fi.le.rar".match(/\.[^.]+$/);
var path = "http://max/fi.le.rar";
var extention = path.substring(path.lastIndexOf("."), path.length);
I did a test with substring and split from @wisdom.
After 500000 times:
.rar Execution time: 47ms (sub)
rar Execution time: 53ms (split without dot)
(after some more testing the execution times are about the same)
I have no experience with match