描述:
图片地址为:
"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"));