如何匹配特定所有<li>标签之间的内容?

Raj*_*Raj 3 php regex

如何匹配以下HTML代码中的所有<li>标记:

<ul>
<li> some content</li>
<li> some other content</li>
<li> some other other content.</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

此表达式不起作用:

<LI>(.*)</ LI>

因为它返回:

some content</li>
    <li> some other content</li>
    <li> some other other content.
Run Code Online (Sandbox Code Playgroud)

这是第一个<li>和最后一个</ li>之间的内容

Jas*_*ary 6

正则表达式本质上是贪婪的.通过添加来使其变得非贪婪?.

<li>(.*?)</li>
Run Code Online (Sandbox Code Playgroud)

注意:我鼓励使用DOM Parser来做这样的事情.查看PHP的DOMDocument.