 <p>You can get the extensions for all links in a document like this:</p> <pre><code>var endings = []; var links = document.getElementsByTagName("a"); var matches; for (var i = 0; i &lt; links.length; i++) { if (links[i].href) { matches = links[i].href.match(/\.([^\.]+)$/); if (matches) { endings.push(matches[1]); } } } // the array endings contains a list of all link extensions </code></pre> <p>Here's a working version of the code: <a href="http://jsfiddle.net/jfriend00/XHKaT/" rel="nofollow">http://jsfiddle.net/jfriend00/XHKaT/</a></p> <p>The regular expression here matches a period followed by one or more non-period characters at the end of the string. The parenthesized grouping allows us to extra just the extension without the period which accomplishes the result you outlined.</p>