JSFiddle - React, Tailwind, and code Playground
JavaScript
// Experiment with the replace function and a lambda expression.
var str = "i am*happy all the*time",
rex = [
/(\S)\s*\*\s*(\S)/g
],
i = 0,
r = rex.length;
for (i; i < r; i += 1) {
str.replace(rex[i], function(star, p1, p2) {
console.log(i, star, p1, p2);
return p1 + '\\s*(.*)\\s*' + p2;
});
}
// should say:
// i am*\\s*(.*)\\s*happy all the\\s*(.*)\\s*time
document.body.innerHTML += str;