Reputation: 1669
I have the following string.
var str = "\\Desk-7\e\cars\car1.jpg";
I want to get car1.jpg
. How can i get that using jquery or javascript
Upvotes: 1
Views: 119
Reputation: 9947
first split then get it
var abc[] = str.split("\\")
var name = abc[abc.length-1];
Upvotes: 1
Reputation:
"\\Desk-7\e\cars\car1.jpg".match(/\b[^/]+$/); //["Desk-7ecarscar1.jpg"]
Upvotes: 1
Reputation: 4904
Or could be done with:
var str = "\\\\Desk-7\\e\\cars\\car1.jpg";
var name = str.slice(str.lastIndexOf("\\") + 1);
Upvotes: 2
Reputation: 74420
NOTE: str should be: var str = "\\\\Desk-7\\e\\cars\\car1.jpg";
if hardcoded in code
var car1 = str.split('\\').pop();
Upvotes: 6
Reputation: 8065
Can be done by
function basename(path) {
return path.replace(/\\/g,'/').replace( /.*\//, '' );
}
Upvotes: 2