[EDIT] First of all: I am aware that by DOM manipulation tools you can easily modify DOM structures. (These are available in every browser and even in Node by third party libraries.)
The goal of his question is if someone can come up with a clever idea if this problem can be solved by Regexp in JavaScript without DOM.
Thank you![End of EDIT]
Let's say I have the following HTML snippet as a string:
<p>
<div class="something">
<span>
<div class="else">My precious text.</div>
</span>
</div>
</p>
I wish to get rid of the <div class="something">
tags with RegExp in order to get something like this (indentation does not matter):
<p>
<span>
<div class="else">My precious text.</div>
</span>
</p>
So, my attempt was:
htmlString.replace(/<div class="something">([\s\S]+?)<\/div>/gi, "$1");
But it will match for the closing tag of <div class="else">
of course.
How can I do it properly using just vanilla JS and by not using the DOM manipulation tools of the browser? (i.e. in Node)