How to pull the file name from a url using javascript/jquery?

Posted by jim23 on Stack Overflow See other posts from Stack Overflow or by jim23
Published on 2009-08-19T19:59:31Z Indexed on 2010/06/07 23:22 UTC
Read the original article Hit count: 162

Filed under:
|
|

A certain variable might contain a relative path or an absolute path. Either way, I need to be able to pull the filename from the variable:

http://www.somesite.com/dir1/dir2/filename.gif
/dir1/dir2/filename.gif

The directory structure is also arbitrary. So basically given either of the url's above (with arbirtrary directory structure) I need to pull 'filename.gif'. Thanks in advance

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery