title: Strange behavior of regexp in JavaScript
body: <p>I wrote a simple JavaScript function to split a file name into parts: given a file name of the type 'image01.png' it splits it into 'image', '01', 'png'. </p>
  
  <p>For this I use the following regular expression:</p>
  
  <pre><code>var reg = /(\D+)(\d+).(\S+)$/;
  </code></pre>
  
  <p>This works. </p>
  
  <p>However, I would like to be able to split also something like this: day12Image01.png into 'day12Image', '01', 'png'. Generally, I would like to have any number of additional digits associated to the body as long as they do not fall right before the extension. </p>
  
  <p>I tried with:</p>
  
  <pre><code>var reg = /(.+)(\d+).(\S+)$/;
  </code></pre>
  
  <p>or the alternative:</p>
  
  <pre><code>var reg = /(\S+)(\d+).(\S+)$/;
  </code></pre>
  
  <p>Confusingly (to me), if I apply those regular expressions to 'image01.png' I get following decomposition: 'image0', '1', 'png'.</p>
  
  <p>Why is the '0' being assigned to the body instead of the numerical index in these cases?</p>
  
  <p>Thanks for any feedback.</p>