<?php
$str = "This is some random text, tag1{while this is inside a tag2{tag}}. This is some other text tag2{also with a tag  tag3{inside} of it}.";

$re = "/\\b(\\w+)(?={((?:[^{}]+|{(?2)})*)})/";
preg_match_all($re, $str, $m);

echo "* Tag names:\n";
print_r($m[1]);
echo "* Tag content:\n";
print_r($m[2]);
?>