title: Using replace and regex to capitalize first letter of each word of a string in JavaScript
body: <p>The following,though redundant, works perfectly :</p>
  
  <p><code>'leap   of, faith'.replace(/([^ \t]+)/g,"$1");</code></p>
  
  <p>and prints "leap   of, faith", but in the following : </p>
  
  <p><code>'leap   of, faith'.replace(/([^ \t]+)/g,RegExp.$1);</code> it prints "faith faith faith" </p>
  
  <p>As a result when I wish to capitalize each word's first character like:</p>
  
  <p><code>'leap   of, faith'.replace(/([^ \t]+)/g,RegExp.$1.capitalize());</code></p>
  
  <p>it doesn't work. Neither does, </p>
  
  <p><code>'leap   of, faith'.replace(/([^ \t]+)/g,"$1".capitalize);</code> </p>
  
  <p>because it probably capitalizes "$1" before substituting the group's value. </p>
  
  <p>I want to do this in a single line using prototype's capitalize() method</p>