Hello,

I am currently passing some HTML through to preg_match and I want to access all the HTML between two tags, however as the same tags may be repeated afterwards my current expression isn't working. For example, my expression at the moment is

<li>(.*)</li>

But as the HTML is like this:

<li><!-- A bunch of HTML in here --></li>
<li><!-- More HTML in here --></li>

It picks up everything between the first <li> and the very last </li>

I've been trying to think of a means of solving this for hours but I am well and truly stuck, does anyone have any idea on how I may be able to overcome this issue?

Thanks

Add the lazy quantifier:

<li>(.*?)</li>

pritaeas, that works perfectly! Will the lazy quantifier always attempt to cut the match as short as possible? i.e. is it looking for an instance of </li> and when doing so ending the match?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.