title: Regex to get a filename from a url
body: <p>I am trying to write a regex to get the filename from a url if it exists.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>(?:[^/][\d\w\.]+)+$
  </code></pre>
  
  <p>So from the url <code>http://www.foo.com/bar/baz/filename.jpg</code>, I should match <code>filename.jpg</code></p>
  
  <p>Unfortunately, I match anything after the last <code>/</code>.</p>
  
  <p>How can I tighten it up so it only grabs it if it looks like a filename?</p>