I want to select DIV(s) with specific class and all its content even if its includes another DIV elements. I cannot find any good regex for this in JS. The code below should return 2 DIVs.
var content = document.querySelector('textarea').value;
var matches = content.match(/<div class\="custom">(.*?)<\/div>/g);
console.log(matches);
textarea {
width: 100%;
height: 200px;
}
<textarea><div><div class="custom"><p>TEST</p><div>Another inner div</div><div class="another-class">Some text</div></div></div>
<p>Another text</p>
<div><div class="hello"><div class="custom another" data-custom="test-data"><div>Another inner div</div><p>TEST</p><div class="another-class">Some text</div></div></div></div></textarea>
Or for testing also: https://regex101.com/r/5TEMRq/1