const regex = /(?s)(\G|<p class="oyric">)((?!</p>).)*?\K((?<=>)\h+|\h+(?=<|\h))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?s)(\\G|<p class="oyric">)((?!<\/p>).)*?\\K((?<=>)\\h+|\\h+(?=<|\\h))', 'gm')
const str = ` <div align="justify">
<table width="552" border="0">
<tr>
<td><h1 class="article" itemprop="name">Modals</h1></td>
</tr>
<tr>
<td class="text_dreapta">On February 25, 2011, in <a href="modals.html" title="View all articles from Modals" class="external" rel="category tag">Destiny</a>, by Roland Worrior</td>
</tr>
</table>
<p class="text_obisnuit2"><em>Should I stay or should I go?</em></p>
<p class="oyric"> Laurie Strode comes to her final confrontation with Michael Myers, the masked figure who has haunted her since she narrowly escaped. </p>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions