Regular Expression Help - Brackets within brackets

Posted by adbox on Stack Overflow See other posts from Stack Overflow or by adbox
Published on 2010-03-15T00:07:29Z Indexed on 2010/03/15 0:09 UTC
Read the original article Hit count: 319

Filed under:

Hello

I'm trying to develop a function that can sort through a string that looks like this:

Donny went to the {park|store|{beach with friends|beach alone}} so he could get a breath of freash air. 

What I intend to do is search the text recursively for {} patterns where there is no { or } inside the {}, so only the innermost sandwiched text is selected, where I will then run a php to array the contents and select one at random, repeating process until the whole string has been parsed, showing a complete sentence.

I just cannot wrap my head around regular expressions though.

Appreciate any help!

© Stack Overflow or respective owner

Related posts about php