title: Regex to find <a> tags containing links to specific file types
body: <p>I am trying to write a small jQuery / javascript function that searches through all the links on a page, identifies the type of file to which the  tag links, and then adds an appropriate class. The purpose of this task is to style the links depending on the type of file at the other end of the link.</p>
  
  <p>So far I have this:</p>
  
  <pre><code>$(document).ready(function(){
      $('#rt-mainbody a').each(function(){
          linkURL = $(this).attr('href');
          var match = linkURL.match("^.*\.(pdf|PDF)$");
          if(match != null){$(this).addClass('pdf');}
      });
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/jLXrf/" rel="nofollow">Fiddle me this.</a></p>
  
  <p>And then I would continue the concept to identify, for example, spreadsheet files, Word documents, text files, jpgs, etc.</p>
  
  <p>it works... but the thing is, to me this is super clunky because I have completely botched it together from odds and sods I've found around SO and the internet - I'm sure there must be a neater, more efficient, more readable way of doing this but I have no idea what it might be. Can someone give it a spit and polish for me, please?</p>
  
  <p>Ideally the function should detect (a) that the extension is at the end of the href string, and (b) that the extension is preceded by a dot.</p>
  
  <p>Thanks! :)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Wow! Such a response! :) Thanks guys!</p>
  
  <p>When I saw the method using simply the selector it was a bit of a facepalm moment - however the end user I am building this app for is linking to PDFs (and potentially other MIMEs) on a multitude of resource websites and has no control over the case usage of the filenames to which they'll be linking... using the selector is clearly not the way to go because the result would be so inconsistent.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>And the grand prize goes to @Dave Stein!! :D</p>
  
  <p>The solution I will adopt is a "set it and leave it" script (<a href="http://jsfiddle.net/dDMKK/1/" rel="nofollow">fiddle me that</a>) which will accommodate any extension, regardless of case, and all I need to do is tweak the CSS for each reasonable eventuality.</p>
  
  <p>It's actually nice to learn that I was already fairly close to the best solution already... more through good luck than good judgement though XD</p>