title: Regular expression to replace words preserving spaces
body: <p>I'm trying to develop a function in javascript that get a phrase and processes each word, preserving whiteSpaces. It would be something like this:</p>
  
  <pre><code>properCase('  hi,everyone   just  testing') =&gt; '  Hi,Everyone   Just  Testing'
  </code></pre>
  
  <p>I tried a couple of regular expressions but I couldn't find the way to get just the words, apply a function, and replace them without touching the spaces.</p>
  
  <p>I'm trying with</p>
  
  <pre><code>'  hi,everyone   just  testing'.match(/([^\w]*(\w*)[^\w]*)?/g, 'x')
  ["  hi,", "everyone   ", "just  ", "testing", ""]
  </code></pre>
  
  <p>But I can't understand why are the spaces being captured. I just want to capture the (\w*) group. also tried with <code>/(?:[^\w]*(\w*)[^\w]*)?/g</code> and it's the same...</p>