<?php
$str = 'aaa(bbb(x), ccc()';
$repl = preg_replace('/ ( \( (?: [^()]* | (?1) )* \) ) /x', '', $str);
var_dump($repl);
$matched = '';
if (preg_match('/\w+(?=[^\w(]*\([^(]*$)/', $repl, $arr))
   $matched = $arr[0];
echo "*** Matched: [$matched]\n";
?>