I need get from string, piece after last \
or /
, that is from this string C:\fake\path\some.jpg
result must be some.jpg
I tried this:
var str = "C:\fake\path\some.jpg";
var newstr = str.replace(/[^\\\/]+$/, "");
alert(newstr);
http://jsfiddle.net/J4GdN/3/
but not works, what is right regex for this?
You don't need a regex to do it, this should work:
var newstr = str.substring(Math.max(str.lastIndexOf("\\"), str.lastIndexOf("/")) + 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With