3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; }
based on taQYB
Output for 4.3.0 - 7.1.0
array ( 0 => '$a * 10 + $b', 1 => '10 + 2', )