I have texts coming from the database that need to be modified before displaying them.
E.g. as seen below, in the code block, a text can have one or multiple {variables} that need to be replaced by html <i>
tag with a class name that comes from the variable.
const string = 'Lorem ipsum dolor sit {icon_exit} consectetur {icon_plus} elit.';
const matched = string.match(/{(.*?)}/g); //["{icon_exit}", "{icon_plus}"]
//... replace both with `<i class="icon-${exit or plus}"></i>`
return string; //Lorem ipsum dolor sit <i class="icon-exit"></i> consectetur <i class="icon-plus"></i> elit.