 <p>I'd suggest:</p> <pre><code>var link = 'http://www.example.com/directory1/directory2/directory3/directory4/index.html'; console.log(link.split('/')[5]);​ </code></pre> <p><a href="http://jsfiddle.net/Eubmg/" rel="nofollow">JS Fiddle demo</a>.</p> <p>The reason we're using <code>[5]</code> not <code>[4]</code> is because of the two slashes at the beginning of the URL, and because JavaScript arrays are zero-based.</p>