title: Return integer from string in JavaScript
body: <p>So I have the following string</p>
  
  <pre><code>var str = "Ana has 27 apples";
  </code></pre>
  
  <p>Is there any function that can return only the number 27 from <code>str</code> as an integer ?</p>
  
  <p>I have found an old thread here about something like this but it was about Java. However it got me into <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions" rel="nofollow noreferrer">Regular Expressions</a>.</p>
  
  <p>And I went ahead and tried playing with this but nothing gone as I expected..
  This is the last expression I tried before coming here: </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>    var str = "Ana has 27 apples";
      var regex = /([0-9])\d+/;
      var ret = str.match(regex);
      console.log(ret);</code></pre>
  </div>
  </div>
  </p>
  
  <p>And it returns 27,2 but I don't want that 2 returned  and I definitely do not want it as a string.
  The thing is that the number is not necessary 27 , its a given number and it can be any integer.</p>
  
  <p>So can it be done with Regular Expressions or is there another ("better") way of doing it without supplimentary lines of code?</p>