var text = "This is simple html text is split by a script tag <script language='javascript'>simple simple text text <script> text.Note I want don't want to lost my original text var. I just want to replace 'simple' word with 'myword' but not inside script tag as well content of script tag";
I want to replace all 'simple' words with 'myword' in text string but not inside script tags content. I have tried but it's not working
var searchMask = 'simple';
var regEx = new RegExp("(" + searchMask + ")(?!([^<]+)?>)", "gi");
var result = text.replace(regEx, "myword");
Output that I want to get:-
This is myword html text is split by a script tag <script language="javascript">simple simple text text </script> text.Note I don't want to loose my original text var. I just want to replace 'myword' word with 'myword' but not inside script tag as well content of script tag