Using HTML template String and Regex'ing dynamic values. Stuck on regex
<p>I am getting stuck. Perhaps there is a better way with the regex (like to hear your thoughts).</p>

<p>AS a ONE-OFF the following works if I am just subbing in one thing, say -link-.</p>

<pre><code>var testHtmlStr = '&lt;tr&gt;' +
                '&lt;td class="eve"&gt;&lt;div class="pad" style="overflow:hidden;"&gt;' +
                  '&lt;a href="#" class="pic"&gt;&lt;img height="50" width="80" title="{%desc%}" alt="{%desc%}" src="{%image%}"&gt;&lt;/a&gt;' +
                  '&lt;div class="sum"&gt;&lt;a href="{%link%}" class="url"&gt;{%name%}&lt;/a&gt;&lt;/div&gt;' +
                  '{%star_rating_html%}' +
                  '&lt;a href="#" class="gray"&gt;{%eventC%}&lt;/a&gt;' +
                  '&lt;span class="block"&gt;{%evenC%}&lt;/span&gt;' +
                '&lt;/div&gt;&lt;/td&gt;' +
                '&lt;td class="mor"&gt;&lt;div class="pad"&gt;&lt;a class="mor" href="{%link%}"&gt;{%linkName%}&lt;/a&gt;' +
                '&lt;/div&gt;&lt;/td&gt;' +
              '&lt;/tr&gt;';
var ss = 'link';
var syntax = new RegExp('(^|.|\r|\n)(\{%\s*(' + ss + ')\s*%\})',"gi");

 alert(testHtmlStr.replace(syntax, '$1TESTESTESTESTS'));
</code></pre>

<p>The following is my code and it DOES NOT WORK. I can't figure out why. Same regex, same html template pattern. Also, my .each reiterates thru the string, but it seems after every reiteration the string returns to its unmodified state. Basically, whatever is the html string like so {%somehashkey%}, I want it to be replaced with the corresponding hash value.
I figured my code would work, can't figure out what is wrong. Something is out of wack, I know that. I can't hunt it down. Your thoughts?</p>

<pre><code>(function($){
var testHTML2 = '&lt;tr&gt;' +
                '&lt;td class="eve"&gt;&lt;div class="pad" style="overflow:hidden;"&gt;' +
                  '&lt;a href="#" class="pic"&gt;&lt;img height="50" width="80" title="{%desc%}" alt="{%desc%}" src="{%image%}"&gt;&lt;/a&gt;' +
                  '&lt;div class="sum"&gt;&lt;a href="{%link%}" class="url"&gt;{%name%}&lt;/a&gt;&lt;/div&gt;' +
                  '{%rating%}' +
                  '&lt;a href="#" class="gray"&gt;{%eventC%}&lt;/a&gt;' +
                  '&lt;span class="block"&gt;{%evenC%}&lt;/span&gt;' +
                '&lt;/div&gt;&lt;/td&gt;' +
                '&lt;td class="mor"&gt;&lt;div class="pad"&gt;&lt;a class="mor" href="{%link%}"&gt;{%linkName%}&lt;/a&gt;' +
                '&lt;/div&gt;&lt;/td&gt;' +
              '&lt;/tr&gt;';

var type = "yahoo";
var disp = {};
disp.eventC = '5';
disp.rating = "&lt;div&gt;rating here&lt;/div&gt;";
switch (type) {
case 'yahoo':
    disp.link = 'http://www.yahoo.com';
    disp.image = 'SOMe IMAGE' ;
    disp.name = "VENICE BEACH";
    disp.desc = 'MORE INFO&amp;nbsp;';
    disp.linkName = 'YAHOO';
break;
default:
    disp.link = 'http://www.google.com';
    disp.image = 'Some IMAGE';
    disp.name = "BABY BABY";
    disp.desc = 'MORE INFO&amp;nbsp;YOYOYO';
    disp.linkName = 'GOOGLE';
}

$.each( disp, function(t, num){
var syntax = new RegExp('(^|.|\r|\n)(\{%\s*(' + t + ')\s*%\})',"gi");
testHTML2.replace(syntax, num)
});
alert(testHTML2);
})(jQuery);
</code></pre>
