3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "this (is (a) test) with (two parenthesis) duh"; $regex = '#\((([^()]+|(?R))*)\)#'; if (preg_match_all($regex, $string ,$matches)) { echo var_export($matches[1], true); } else { //no parenthesis echo $string; }

preferences:
34.45 ms | 402 KiB | 5 Q