const regex = new RegExp('(?><a.*?>(.*?)</a>)\\s*<ul', '')
const str = `<ul>
<li>
<a href="#o">Первый</a>
</li>
<li>
<a href="#v">Второй</a>
</li>
<li>
<a href="#t">Третий</a>
</li>
<li>
<a href="#ch">Четвертый</a>
</li>
<li>
<a href="#p">ПÑтый</a>
</li>
<li>
<a href="#test">ШеÑтой</a>
<ul>
<li>
<a href="#so">ШеÑтьОдин</a>
</li>
<li>
<a href="#sd">ШеÑтьДва</a>
</li>
<li>
<a href="#st">ШеÑтьТри</a>
</li>
<li>
<a href="#sc">ШеÑтьЧетыре</a>
</li>
<li>
<a href="#sp">ШеÑтьПÑть</a>
</li>
<li>
<a href="#ss">ШеÑтьШеÑть</a>
</li>
<li>
<a href="#sss">ШеÑтьСемь</a>
</li>
<li>
<a href="#sv">ШеÑтьВоÑемь</a>
</li>
<li>
<a href="#sd">ШеÑтьДевÑть</a>
</li>
</ul>
</li>
</ul>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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