title: How can I extract a number from a string in JavaScript?
body: <p>I have a string in JavaScript (e.g <code>#box2</code>) and I just want the <code>2</code> from it.</p>
  <p>I tried:</p>
  <pre><code>var thestring = $(this).attr('href');
  var thenum = thestring.replace( /(^.+)(\w\d+\w)(.+$)/i,'$2');
  alert(thenum);
  </code></pre>
  <p>It still returns <code>#box2</code> in the alert, how can I get it to work?</p>
  <p>It needs to accommodate for any length number attached on the end.</p>