Sorry for unclear description, my English is not good.
My problem is that I want to decode a string, and this string has nested content delimited by {}.
For example:The string:
{any string0{any string 00{any string 000....}}}{any string1}any str开发者_StackOverflowing.
The result I want to get:
array[0] = {any string0{any string 00{any string 000....}}}
array[1] = {any string1}
I hope it's clear enough.
Making the best use of the (oddly put, and hopefully soon-to-be-edited) question, the following takes your example string and provides your example array.
$subject = '{blah\blah{\blah\blah...{\bl....}}}{blah...}blah... ';
$pattern = '/\{(?>[^{}]++|(?R))*\}/';
preg_match_all($pattern, $subject, $matches);
print_r($matches[0]);
Which produces:
Array
(
[0] => {blah\blah{\blah\blah...{\bl....}}}
[1] => {blah...}
)
精彩评论