JSFiddle - React, Tailwind, and code Playground
JavaScript
str = "x <span> z </span> y"
var res = str.replace(/([>]|^)([^<^>]+)([<]|$)/gi, function (match) {
return match[1] + match[2] + "!" + match[3]
});
console.log(res);
str = "x <span> z </span> y"
var res = str.replace(/([>]|^)([^<^>]+)([<]|$)/gi, function (match) {
return match[1] + match[2] + "!" + match[3]
});
console.log(res);