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 qJOIB
Output for 5.0.4 - 7.1.0
Notice: Undefined variable: a in /in/taQYB on line 2 Notice: Undefined variable: b in /in/taQYB on line 2 array ( 0 => ' * 10 + ', 1 => '10 + 2', )
Output for 4.3.0 - 5.0.3
Notice: Undefined variable: a in /in/taQYB on line 2 Notice: Undefined variable: b in /in/taQYB on line 2 array ( 0 => ' * 10 + ', 1 => '10 + 2', )