Q:

Jquery replace string element by delimiter

I've a string like this
var str = "<div class=\"@@obj.classname@@\" style="\@@obj.color@@\">@@obj.content@@</div>";

I'd like to create a function to dynamically change it and get this result
var result = "<div class=\"" + opt.obj.classname + "\" style="\" opt.obj.color + "\">" + opt.obj.content + "</div>";

Is it possibile to do it? How could I do that? the replace function might help? Thank you

A:

You can use eval to execute some code in a string. Before that, you need to make sure your string is proper code, so you would need to replace the @@parameter@@ with the parameter wrapped with ' and +. Something like this:
var str = "'" + str.replace(/@@(.*?)@@/g, "' + opt.$1 + '") + "'";
var result = eval(str);

Working example: https://jsfiddle.net/hj3grh1o/

