JSFiddle - React, Tailwind, and code Playground

by Alexey Demin

JavaScript

var replacements = {
    "%NAME%": "Mike",
    "%AGE%": "26",
    "%EVENT%": "20"
},
    str = 'My Name is %NAME% and my age is %AGE%, the following %TOKEN% is invalid.';

str = str.replace(/%\w+%/g, function(all) {
    return replacements[all] || all;
});

document.body.innerHTML = str;