title: Using replace to select part of a URL
body: <p>Hello I'm new to javascript and I need a little help with regex/replace</p>
  
  <p>I want to take a url for example (url case 1)</p>
  
  <blockquote>
    <p><a href="http://url.com/_t_lastUpdate_2670619?location=50457347" rel="nofollow noreferrer">http://url.com/_t_lastUpdate_2670619?location=50457347</a></p>
  </blockquote>
  
  <p>or (url case 2)</p>
  
  <blockquote>
    <p><a href="http://url.com/_t_2670619" rel="nofollow noreferrer">http://url.com/_t_2670619</a></p>
  </blockquote>
  
  <p>I want to select in this case just</p>
  
  <pre><code>_t_2680619
  </code></pre>
  
  <p>Ignore everything after "?" and before (underscore)t(underscore)</p>
  
  <p>Is it possible with regex/replace? the only thing I managed to do was select numbers only with</p>
  
  <pre><code>var _t__and_number = document.URL.replace(/[^\d]/g, '');
  alert(_t__and_number);
  </code></pre>
  
  <p>But that doesn't solve my problem if there's something like url case 1</p>
  
  <p>(if I could get just the first number even without the (underscore)t(underscore) it would already help me a lot.
  Thanks</p>
  
  <h1>Solutions:</h1>
  
  <p><a href="https://stackoverflow.com/questions/18198899/using-replace-to-select-part-of-a-url#comment26671396_18198899">onetrickpony</a>/michaelb958:</p>
  
  <pre><code>var _t__and_number = window.location.pathname;
  alert(_t__and_number);
  </code></pre>
  
  <p>ermagana:</p>
  
  <pre><code>var _t__and_number = document.URL.replace(/\?.*/g, '').match(/.*\/(.*)/)[1];
  alert(_t__and_number);
  </code></pre>