3v4l.org

run code in 300+ PHP versions simultaneously
<?php $re = '/{@(?<func>\w+)(\((?<params>(?:[^()]++|(?2))*)\))}/u'; $str = 'строка с {@rand(1||{@rand(2|3|{@rand(4|5)})})} и {@rand(1|{@rand(2|3|{@rand(4|5)})})}.'; if (preg_match_all($re, $str, $matches, 0, PREG_SET_ORDER)) { print_r($matches["func"]); print_r($matches["params"]); }

preferences:
10.86 ms | 408 KiB | 5 Q