title: Why does string.replace(/\W*/g,'_') prepend all characters?
body: <p>I've been learning regexp in js an encountered a situation that I didn't understand.</p>
  
  <p>I ran a test of the replace function with the following regexp:</p>
  
  <pre><code>/\W*/g
  </code></pre>
  
  <p>And expected it prepend the beginning of the string and proceed to replace all non-word characters.</p>
  
  <pre><code>The Number is (123)(234)
  </code></pre>
  
  <p>would become:</p>
  
  <pre><code>_The_Number_is__123___234_
  </code></pre>
  
  <p>This would be prepending the string because it has at least zero instances, and then replacing all non-breaking spaces and non-word characters.</p>
  
  <p>Instead, it prepended every character and replaced all non-word characters.</p>
  
  <pre><code>_T_h_e__N_u_m_b_e_r__i_s__1_2_3__2_3_4__
  </code></pre>
  
  <p>Why did it do this?</p>