I need to create a function like Douglas Crockford's String.supplant:
if (typeof String.prototype.supplant !== 'function') {
String.prototype.supplant = function (o) {
return this.replace(/{([^{}]*)}/g, function (a, b) {
var r = o[b];
return typeof r === 'string' ? r : a;
});
};
}
what it does is:
var html = '<div>{title}<h3>{time}</h3><p>{content}</p></div>';
var object = {title: "my title", time: "12h00m", content:"blablabla"}
supplanted = html.supplant(object);
//supplanted returns:
//<div>my title<h3>12h00m</h3><p>blablabla</p></div>
i need, for a project for my tags to be different: instead of {tagname}
, i need it to be [ns:tagname]
does anyone here have enough knowledge of regular expressions to help me out?
thank you very much