I am attempting to replace some custom variable tags in a content block with values from an array. I currently have some working code that is successfully replacing variables that look like %([variable_name])% however, I need it to replace variables that look like <%[variable_name]%>. I have been messing around with the following code for a few hours, and I'm having trouble wrapping my head around the regex portions, and getting it to work correctly with my new variable format.
Here is the code that currently works for %([variable_name])%, how can I get it to work for <%[variable_name]%>?
$.each(data, function(key, value){
var our_key = "%(["+key+"])%";
our_key = our_key.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
var regex = new RegExp(our_key, 'g');
new_contents = new_contents.replace(regex,value);
});
Edit: The real problem was that I was grabbing my "new_contents" using the jquery '.html()' attribute, which was replacing my '<' and '>' with '& lt;' and '& gt;'