We have a HTML string where we have a list. Something like shown below
<ul><li>Item A</li><li>Item B</li><li>Item C</li><li>Item D</li></ul>
Here is the formatted version of the same.
<ul>
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
<li>Item D</li>
</ul>
My objective is to write a regular expression to select the first two items for the list. So the output should be
<ul>
<li>Item A</li>
<li>Item B</li>
</ul>
If that's not possible to do it in regex, what will be a most optimized way to do it through plain javascript code.
and match- s
– Alex Apr 20 '22 at 04:46