3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '($a * 10 + $b) Euro and (10 + 2) cents'; $regex = '#\((([^()]+|(?R))*)\)#'; if (preg_match_all($regex, $string ,$matches)) { echo var_export($matches[1], true); } else { //no parenthesis echo $string; }

preferences:
38.06 ms | 402 KiB | 5 Q