javascript strings

Hi

I have a string:

url("file:///C:/Users/langlp/Desktop/BMW%20demo/img/36_bw.jpg")


I want to get the image name "36_bw.jpg". How do i get this with javascript?

Thanks
coolispaulAsked:
Who is Participating?
 
stergiumConnect With a Mentor Commented:
hello

var a='url("file:///C:/Users/langlp/Desktop/BMW%20demo/img/36_bw.jpg")';
var b=a.indexOf(')');
var c=a.lastIndexOf('/');
console.log(a.substring((c+1),(b-1)));

Open in new window


change the console log to whatever you need. hope that helps
0
 
leakim971PluritechnicianCommented:
Test page : http://jsfiddle.net/b3L5z/

var img = str.match(/img\/([^.]*\.jpg)/).pop();

Open in new window

0
 
coolispaulAuthor Commented:
perfect thanks guys
0
 
Alex_WCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.