3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $trim = function($str) { return preg_replace('~\(+(\(((?:[^()]*|(?1))*)\))\)+|(\((?:[^()]*|\g{-1})*\))~', '$2$3', $str); }; echo $trim('((((A))))'), "\n"; echo $trim('(((((B+C)*A)*(F))))'), "\n"; echo $trim('(A+B)(B+C)'), "\n"; echo $trim('(((((B+C)*A))))'), "\n"; echo str_repeat('-',15), PHP_EOL; echo $trim('((A+B)+C)'), "\n"; echo $trim('(((A+B))+C)'), "\n"; echo $trim('((((A+B))+C))'), "\n"; echo $trim('(A+(B+C))'), "\n"; echo $trim('(A+((B+C)))'), "\n";
based on ANC7P
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0rc3
A ((B+C)*A)*(F) (A+B)(B+C) (B+C)*A --------------- ((A+B)+C) A+B+C) A+B+C)) (A+(B+C)) (A+B+C