I use split to insert javascript generated text into html text, but I need to skip parts like html tags </><\> , so after a lot of searching, I found this:
var = var.replace(/<\/?[\w#"'-=:; {},.\r\n]+\/?>/g, '\n');
the problem is that it does not skip tags or anything that is specified in this variable, it actually replaces the tags with a space.
What I need to achieve, for example:
<script>random javascript</script><p>my text</p> --- New text that needs to be inserted ---
What is currently happening:
my text</p> --- New text that needs to be inserted ---
As you can see, the first tags (The javascript) are not skipped, they are deleted.
Which method should be used instead of replacing?
source share