描述:
圖片地址為:
"http://snowinmay.net/img/dada.jpg"
圖片名稱:
dada.jpg
======================
方法一:用js的split方法:
var url = "http://snowinmay.net/img/dada.jpg";
var reg = /\/.*[^\/]$/g;
var arr = url.split('/');
console.log(arr[arr.length-1]);
方法二:用lastIndexOf和substr:
var index = url.lastIndexOf("/");
console.log(url.substr(index+1));
方法三:正規表示式:
var url = "http://snowinmay.net/img/dada.jpg";
var fullpath = "D:\\pic\\02.jpg";
var reg2 = /^.+\\([^\\]+)$/;
var reg3 = /^.+\/([^\/]+)$/;
var filename = fullpath.replace(reg2,"$1");
console.log(filename);
console.log(url.replace(reg3,"$1"));