fork(2) download
  1. <?php
  2. $str = 'aaa(bbb(x), ccc()';
  3. $repl = preg_replace('/ ( \( (?: [^()]* | (?1) )* \) ) /x', '', $str);
  4. var_dump($repl);
  5. $matched = '';
  6. if (preg_match('/\w+(?=[^\w(]*\([^(]*$)/', $repl, $arr))
  7. $matched = $arr[0];
  8. echo "*** Matched: [$matched]\n";
  9. ?>
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
string(12) "aaa(bbb, ccc"
*** Matched: [aaa]