Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
<li id="hit-[0-9]+">(.*?)<\/li>
/
is

Description

I need to find the fastest expression to get all the list items inside a <ol> an put the items inside an array.

input:

<ol class="searchresult"> <li id="hit-2"> <h2> <a href="http://www.xxx.com" class="heading">xxx</a> </h2> <p>xxx</p> </li> <li id="hit-1"> <h2> <a href="http://www.xxx.com" class="heading">xxx</a> </h2> <p>xxx</p> </li> ... </ol>

Output:

Array ( 0 => "<h2> <a href="http://www.xxx.com" class="heading">xxx</a>

</h2> <p>xxx</p>" 1 => "<h2> <a href="http://www.xxx.com" class="heading">xxx</a> </h2> <p>xxx</p>" .... );
Submitted by Sonny - 10 years ago