title: Issues with indexOf and lastIndexOf on substring - Get Part of URL from string
body: <p>I'm having a few issues breaking apart a string in the way I want. I have a url like this:</p>
  
  <pre><code>http://SomeAddress.whatever:portWhatever/someDirectory/TARGETME/page.html
  </code></pre>
  
  <p>I'm trying to get the TARGETME portion on the string, using substring and indexOf instead of regex. This is the function I'm working with now:</p>
  
  <pre><code> function lastPartofURL() {
      // Finding Url of Last Page, to hide Error Login Information
      var url = window.location;
      var filename = url.substring(url.lastIndexOf('/')+1);
      alert(filename);
  }
  </code></pre>
  
  <p>However, when I wrote this I was targeting the 'page.html' part, so that's what it returns, but I'm having trouble reconfiguring this to do what I want it to do now.</p>
  
  <p>If possible, I would like it to originate from the beginning of the string rather than the end, as there should always be a url and then one directory before what I'm trying to target, but I'm interested in both solutions.</p>
  
  <p>Here is a regex that does something similar, but it's not secure (according to JSLint), and therefore I wouldn't mind replacing it with something more functional.</p>
  
  <pre><code> /^.*\/.*\/TARGETME\/page.html.*/
  </code></pre>