1. 程式人生 > >js正則匹配獲取檔名

js正則匹配獲取檔名

//獲取檔名,不帶字尾
var file_name=file_path.replace(/(.*\/)*([^.]+).*/ig,"$2");

//獲取檔案字尾
1.var FileExt=file_path.replace(/.+\./,"");

2.var fileExtension = file_path.substring(file_path.lastIndexOf('.') + 1);

//擷取檔案字尾
var reg = /\.\w+$/;
var file_name = file_path.replace(reg,'');