Javascript replace with a regex pattern issue
<p>Please consider the following javascript and html below.<br />
When <code>addAnotherAddress()</code> is run the first time, I'm expecting that all of the <strong>1's</strong> inside <code>&lt;div class="previous_address1"&gt;</code> will be replaced with <strong>2's</strong> and then that html will be appended to <code>&lt;div id="previous_addresses"&gt;</code> but that's not happening when <code>html.replace(pattern, current_address + 1)</code> runs.<br /><br />
What am I doing wrong here?</p>

<p><b>Javascript</b></p>

<pre><code>var current_address = 1; // Used when adding in previous address entries

function addAnotherAddress() {
    var pattern = '/' + current_address + '/g';
    var html = $('.previous_address' + current_address).html();

    html = html.replace(pattern, current_address + 1);

    $('#previous_addresses').append(
        '&lt;div class="previous_address' + (current_address + 1) + '"&gt;' + html + '&lt;/div&gt;' 
    );
    current_address += 1;
}
</code></pre>

<p><b>Html</b></p>

<pre><code>&lt;div id="previous_addresses"&gt;
    &lt;span class="text_line"&gt;
    &lt;u&gt;Previous Addresses for Past 5 Years&lt;/u&gt;
    &lt;/span&gt;
    &lt;div class="previous_address1"&gt;
    &lt;span class="text_line"&gt;
        &lt;i&gt;Address 1&lt;/i&gt;
    &lt;/span&gt;
    &lt;span class="text_line"&gt;
        &lt;label for="previous_street1"&gt;Street:&lt;/label&gt;
        &lt;input type="text" id="previous_street1" /&gt;
    &lt;/span&gt;
    &lt;span class="text_line"&gt;
        &lt;label for="previous_city1"&gt;City:&lt;/label&gt;
        &lt;input type="text" id="previous_city1" /&gt;
    &lt;/span&gt;
    &lt;span class="text_line"&gt;
        &lt;label for="previous_state1"&gt;State:&lt;/label&gt;
        &lt;input type="text" id="previous_state1" /&gt;
    &lt;/span&gt;
    &lt;span class="text_line"&gt;
        &lt;label for="previous_zip1"&gt;Zip:&lt;/label&gt;
        &lt;input type="text" id="previous_zip1" /&gt;
    &lt;/span&gt;
    &lt;span class="text_line"&gt;
        &lt;label for="previous_county1"&gt;County:&lt;/label&gt;
        &lt;input type="text" id="previous_county1" /&gt;
    &lt;/span&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>
