I’m analyzing an innerHTML string and need to remove the < span > and keep the text in between. I use the following code:
const str = 'this <span class="abc">is</span> working';
var str2 = str.replace(/(.*)(<span class="abc">)(.*)(</span>)(.*)/g, "$1$3$5");
str2 is: this is working
This works fine but when I have multiple < span > in the innerHTML string only the last is replaced
const str = 'this <span class="abc">is NOT</span> working and this <span class="abc">is</span> working';
var str2 = str.replace(/(.*)(<span class="abc">)(.*)(</span>)(.*)/g, "$1$3$5");
str2 is: 'this <span class="abc">is NOT</span> working and this is working'
Anny suggestion how to solve this?
Thanks.
Arno