JSFiddle - React, Tailwind, and code Playground

by Alexey Ryazhskikh

JavaScript

str = "x <span> z </span> y"
var res = str.replace(/([>]|^)([^<^>]+)([<]|$)/gi, function (match) {

   return match[1] + match[2] + "!" + match[3]
});

console.log(res);