Jump to content
xisto Community
electron

Regexp Function Preg_match_all() preg_match_all() - Help me

Recommended Posts

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:

 

[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:

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

Now this function gets 2 matches from the given text :

Match 1:

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

Match 2:

[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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.