I have some HTML text like below.
<div style="background:#e0dddd; color:#333399; font:9PT 'arial'; padding:10px; margin-left:-30px; ">
<div>
<strong>Some text here1 </strong><br />
2021-08-08 </div>
<div><p>
Some text here2</p>
</div>
<div class="download">
<a href="index.php?obj=notice_id=1734">View Detail ...</a>
</div>
</div>
<div style="background:#e2ecf4; color:#333399; font:9PT 'arial'; padding:10px; margin-left:-30px; ">
<div>
<strong>Some text 3</strong><br />
2021-08-06 </div>
<div><p>
Some BE text 4.</p>
</div>
<div class="download">
What I'm trying to capture is the following, basically, from the tag <strong> onwards to the line that has BE in it. It can be case insensitive.
Some text 3</strong><br />
2021-08-06 </div>
<div><p>
Some BE text 4.
I'm using /(?<=<strong>)[\s\S]*?b[ _\/,]?e[\W][\s\S]*?(?=<)/gim but it captures the following.
Some text here1 </strong><br />
2021-08-08 </div>
<div><p>
Some text here2</p>
</div>
<div class="download">
<a href="index.php?obj=notice_id=1734">View Detail ...</a>
</div>
</div>
<div style="background:#e2ecf4; color:#333399; font:9PT 'arial'; padding:10px; margin-left:-30px; ">
<div>
<strong>Some text 3</strong><br />
2021-08-06 </div>
<div><p>
Some BE text 4.
What am I doing wrong here?
I suggest a DOM based solution to iterate over the div elements (at the root level). Then a simple test on the inner text suffices to get the good one:
const parser = new DOMParser();
const doc = parser.parseFromString(`<div id="root">${yourhtml}</div>`, 'text/html');
doc.querySelectorAll('#root > div').forEach(function(el) {
let text = el.innerText;
if ( /\bb[^ ,_\/]?e\b/i.test(text) )
console.log(text); // display in your browser console
});