Using $1 as a variable in javascript
<p>I'm trying to parse a customisable block of text, which I load from a file.  Simplifying it a bit, let's say, I'm trying to convert every block of text which appears inside curly brackets into a thing you can click to be javascript-alerted with the aforementioned text.</p>

<p>Problem is, passing $1 into the alert.  $1 doesn't play like a variable.  anyway, it started OK:</p>

<pre><code>var text='Information here: {Thanks for clicking the info link}';
text=text.replace(/{(.+)}/g,'[&lt;span onclick=\"alert(\\'\$1\\')\"&gt;click me&lt;/span&gt;]');
document.write(text);
</code></pre>

<p>So far, so good.  I click where it says "[click me]" and the message "Thanks for clicking the info link" comes up as a javascript alert.</p>

<p>But sometimes I want to put a message with a " or a ' into the curly brackets.</p>

<pre><code>var text='Information here: {Thanks for clicking the "info" link}';
text=text.replace(/{(.+)}/g,'[&lt;span onclick=\"alert(\\'\$1\\')\"&gt;click me&lt;/span&gt;]');
document.write(text);
</code></pre>

<p>simply fails to alert.  If I 'view selection source', it gives:</p>

<pre><code>Information here: [&lt;span onclick="alert('Thanks for clicking the " info"="" link')"=""&gt;click me&lt;/span&gt;]
</code></pre>

<p>I've tried every combination of escaping the " marks, but no joy.</p>

<p>I thought of replacing " with &quot;, but $1 isn't a variable!</p>

<p>Any ideas?  And yes, I do want to do this!  :-)</p>

<p>Thanks!</p>