Skip to content

Instantly share code, notes, and snippets.

@sonyseng
Last active August 29, 2015 13:59
Show Gist options
  • Save sonyseng/10695253 to your computer and use it in GitHub Desktop.
Save sonyseng/10695253 to your computer and use it in GitHub Desktop.
Simple search and replace Templating using Regex
// Example Usage: evalTempl("Hello {name}", {name: "sdg"})
function evalTempl (str, context) {
return str.replace(/\{(.*?)\}/g, function(match, key) {return context[key];});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment