JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://getfirebug.com/firebug-lite.js"></script>

JavaScript

var replacer = function(tpl, data) {
	var re = /\$\(([^\)]+)?\)/g, match;
  while(match = re.exec(tpl)) {
		tpl = tpl.replace(match[0], data[match[1]])
    re.lastIndex = 0;
  }
  return tpl;
}

var html = '<!DOCTYPE html>\
<html lang="en">\
<head>\
  <meta charset="UTF-8">\
  <title>Document $(title)</title>\
</head>\
<body>\
  <h1>Test file, $(text)</h1>\
</body>\
</html>';

var result = replacer(html, { "title" : "my title", "text" : "text is this" });

alert(result);