PDA

View Full Version : need some regex help


bugster
09-24-2007, 08:05 PM
So i've been trying to tackle this task all day yesterday and have not been sucessful. What i need is to use preg_match_all to pull everything from between specific <li> tags. Between these li tags contains other html tags that i want to pull and keep intact.

Example of what i want to pull:

<li class="testClass">
<p>blah</p
<div class="classname" id="blahID">blah</div>
</li>
<li class="testClass">
<p>blah</p
<div class="classname" id="blahID2">blah</div>
</li>

I want everything between each <li></li> tag. If its possible to pull the <li>'s themselves too, then great.

Can someone help me with the regex pattern for this? Thanks

bugster
09-24-2007, 08:45 PM
I think i just got something that worked. Im posting it incase some one might need it:


/<li\b[^>]+?\bclass\s*=\s*\"classNameHere\"[^>]*>(?:((?:[^<]++|<?(?!\/?div\b[^>]*>))+)|(<div\b[^>]*>(?>(?1)|(?2))*<\/div>))?(<\/li>)*/i