<?php $re = "#(?=(\{(?>[^{}]|(?1))*+\}))#"; $str = "Hello {#name}! I'm a {%string|sentence|bit of {#random} text}";
Standard input is empty
Array
(
[0] => Array
(
[0] => {#name}
[1] => 6
)
[1] => Array
(
[0] => {%string|sentence|bit of {#random} text}
[1] => 21
)
[2] => Array
(
[0] => {#random}
[1] => 46
)
)