title: Extract numbers from a string while maintaining the whitespaces
body: <p>I have some string like this</p>
  
  <pre><code>'    12    2    89   29   11    92     92     10'
  </code></pre>
  
  <p>(all the numbers are positive integers so no <code>-</code> and no <code>.</code>), and I want to extract all numbers from it, edit some of the numbers, and then put them all together with the same whitespaces. For example, if I change the number <code>11</code> to <code>22</code>, I want the final string as</p>
  
  <pre><code>'    12    2    89   29   22    92     92     10'
  </code></pre>
  
  <p>I did some search and most questions disregard the whitespaces and only care about the numbers. I tried </p>
  
  <pre><code>match = re.match((\s*(\d+)){8}, str)
  </code></pre>
  
  <p>but <code>match.group(0)</code> gives me the whole string,, <code>match.group(1)</code> gives me the first match <code>\    12</code> (I added the <code>\</code> otherwise the website won't show the leading whitespaces), and <code>match.group(2)</code> gives me <code>12</code>. But it won't give me any numbers after that, any index higher than <code>2</code> gives me an error. I don't think my approach is the correct one, what is the right way to do this?</p>
  
  <p>I just tried <code>re.split('(\d+)', str)</code> and that seems to be what I need. </p>