title: Extract a word in a dynamic string
body: <p>In this example, I want to extract the given price in the string.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const string = 'I am a long sentence! My price is $5,000 on a discount!';
  const price = string.substring(string.lastIndexOf("$")+1,string.lastIndexOf(" "));
  document.write(price);</code></pre>
  </div>
  </div>
  </p>
  
  <p>The above method won't work because it selects the last index of a space (<code>" "</code>)</p>
  
  <p>How do I go about getting the space right after the price ?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>:  </p>
  
  <p>The string might be anything else! I have no control over it, I just want to extract the price. In case I didn't make that clear.</p>