title: Using RegEx to apply a scale factor to a JavaScript string variable
body: <p>I have a string below called "embed"  where I want to modify the width parameter by the scale factor (.8 here). </p>
  
  <pre><code>scale = .8;
  var embed = '&lt;iframe width="960" height="315" src="//www.youtube.com/embed/kk5xfJodtrk" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;';
  </code></pre>
  
  <p>So when I'm done the embed string should read:</p>
  
  <pre><code>embed = '&lt;iframe width="768" height="315" src="//www.youtube.com/embed/kk5xfJodtrk" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;';
  </code></pre>
  
  <p>Actually, width=768, without the quotes,  would also work for me.</p>
  
  <p>I've tried a lot of things.  The latest is</p>
  
  <pre><code>var scale = .8;
  var embed = '&lt;iframe width="960" height="315" src="//www.youtube.com/embed/kk5xfK0ovrk" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;';
  
  var new_embed = embed.replace(/width="(\d+)/,"width=" + scale*$1);
  </code></pre>
  
  <p>But this complains that $1 is not defined.</p>
  
  <p>Thanks for any help.</p>