JSFiddle - React, Tailwind, and code Playground
JavaScript
const s = "hello ! < and ! world>, and ! letter and {another ! letter} here";
const p = s.split(/!(?![^<]*>)(?![^{]*\})/g);
alert(p);
const s = "hello ! < and ! world>, and ! letter and {another ! letter} here";
const p = s.split(/!(?![^<]*>)(?![^{]*\})/g);
alert(p);