JRS: In article <SR************ **********@news .xtra.co.nz>, dated Sat,
18 Feb 2006 10:02:35 remote, seen in news:comp.lang. javascript,
windandwaves <wi*********@co ldmail.com> posted :
I have the following string:
http://www.myurl.com/folderbit/moerf...sdaf/01354.jpg
and I want to extract the filename from it.
Some consider the filename to include the extension; some do not.
S = "http://www.myurl.com/folderbit/moerfiasdfsadf/sdaf/01354.jpg"
S = S.replace(/.+\/(.+)/, "$1") // 01354.jpg
S = S.replace(/.+\/(.+)\..+/, "$1") // 01354
The second presumes that there *is* a non-empty extension; this does
not, but returns only the filename proper :-
S = S.replace(/.+\/([^.]+).*/, "$1")
Consider also
S = S.match(/.+\/([^.]+).*/)[1]
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.