title: Javascript replace() with $1
body: <p>Input string is "thisIsSpinalTap". I replaced each uppercase letter with it's lowercase version. I also wanted to add a - before the letter to get the spinal case effect "this-is-spinal-tap".</p>
  
  <p>I wrote the following line of code:</p>
  
  <pre><code>str = str.replace(/([A-Z])/g, '-').toLowerCase();
  </code></pre>
  
  <p>This replaced each uppercase letter with - to produce "this-s-pinal-ap". This was not the desired effect.</p>
  
  <p>I read that using $1 could produce the effect I wanted, and it did.</p>
  
  <pre><code>str = str.replace(/([A-Z])/g, '-$1').toLowerCase();
  </code></pre>
  
  <p>How does the $1 work to append - to the string, rather than replace the uppercase letter? </p>