I’m doing ‘mustache light’ templating with the data coming out of a database with Javascript. The data looks like this:
As you can see in {{Figure 1-1}}, and again in {{Figures 1-2}} and {{1-3}}, the hozzfrazz is much cleaner than the hooble stick.
My regexp is \{\{[-a-zA-Z0-9\s]+\}\}/gi, which to my mind captures all of the above mustaches. But the only one being recognized in my function is {{1-3}}, not the other two.
Any help?
Apparently I need to add my function as well, since the regex works:
var mReg = new RegExp("\{\{[-a-zA-Z0-9\s]+\}\}");
var link_tpl = "<a href='#' rel='@$' class='questionImageLink'>@@</a>";
var html = '';
var i = 1;
while (mReg.test(mText) === true) {
mText = mText.replace(mReg, function (f) {
var inner = f.substr(2, f.indexOf("}") - 2);
return link_tpl.replace("@@", inner).replace("@$", i);
}, "g");
i++;
}
I would do it like this, using a more forgiving regex and
replaceinstead of thewhilemess.Demo: http://jsfiddle.net/elclanrs/fE3U3/