Hi,

I got a new problem which has caused me to go mad but no solution.
preg_match_all() - is the problem.

I have something like this:

CODE

[ol]
[li]Test1[/li]
[li]Test2[/li]
[li]Test3[/li]
[li]Test4[/li]
[li]Test5[/li]
[/ol]

Some text.Some text.Some text.

[ol]
[li]Test1[/li]
[ol]
[li]Test1[/li]
[li]Test2[/li]
[li]Test3[/li]
[li]Test4[/li]
[li]Test5[/li]
[/ol]
[li]Test2[/li]
[li]Test3[/li]
[li]Test4[/li]
[li]Test5[/li]
[/ol]


My RegExp is the following:
CODE

preg_match_all("/(\[ol\])(.*)(\[\/ol\])/iUx", $text, $matches, PREG_SET_ORDER);


Now this function gets 2 matches from the given text :
Match 1:
CODE
[ol]
[li]Test1[/li]
[li]Test2[/li]
[li]Test3[/li]
[li]Test4[/li]
[li]Test5[/li]
[/ol]


Match 2:
CODE
[ol]
[li]Test1[/li]
[ol]
[li]Test1[/li]
[li]Test2[/li]
[li]Test3[/li]
[li]Test4[/li]
[li]Test5[/li]
[/ol]


It takes the [/ol] of the nested element first.

I wanted that the preg_match_all() function matches the second match including the nested OR it should give me three matches.

If i use Greedy RegExp then it takes the whole thing as One Match including the text between the two seperated [OL]'s.

Is my REGEXP wrong or something.I tried lookaheads also but nothing.

Please help me with this.
I need it . This thing is going in my mind and does not let me live with peace.

Thanks and have a good day.

 

 

 


Reply