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 implode(' ', $matches[1]); } else { //no parenthesis echo $string; }

preferences:
38.26 ms | 402 KiB | 5 Q