How do I match all the <li> tags in the below HTML code:
<ul>
<li> some content</li>
<li> some other content</li>
<li> some other other content.</li>
</ul>
This expression doesn’t work:
<li>(.*)</li>
Because it returns:
some content</li>
<li> some other content</li>
<li> some other other content.
Which is the content between the first <li> and the last </li>
Regular expressions are greedy by nature. Make it non-greedy by adding the
?.Note: I’d encourage a DOM Parser for such a thing. Check out PHP’s DOMDocument.