Click to See Complete Forum and Search --> : pattern matching with URL?


paulrockNJ
08-05-2003, 09:06 AM
I've been trying to do this for a while, and with my completely elementary knowledge of JavaScript I have no idea what to do.

I'm trying to take a URL and extract the filename from it. For example, http://www.domain.com/directory/sub/file.html - I'm trying to extract only the file name, without the extension. So in the case above all i would need is 'file'. Does anybody know how to do this?

Basically I'm trying to make a favelet that will grab the URL of a page on my site, reformat the URL into a specific syntax, and kick that URL over to our CMS, bringing up an editing window. I've gotten as far as to format the host and pathname without the file name and extension, but for the life of me I can't get the file name to exist on its own.

Any help would be greatly appreciated! Examples would be even more appreciated!!! Thanks so much - Paul

AdamBrill
08-05-2003, 09:14 AM
Try this:<script type="text/javascript">
the_string = String(document.location);
the_string = the_string.split('/')[the_string.split('/').length-1].split('.')[0];
alert(the_string);
</script>