$re = '/(?<obj>[a-zA-Z_$][\w.\n]+\.)?(?<func>[a-zA-Z_$][^. ]+)\s*(?<args>\((?:(?:[^()]+)|(?3))*\))/x';
$str = 'var someVar = myValue; object.subob
ject.function(with, some = obj.func(a, b[2][1]), arguments); return true;
// or
var someVar = myValue; object.subobject.function(with, some = obj.fu
nc(a, b[2][1]), arguments); return true;
// or
var someVar = myValue; object.subobject.funct
ion(with, some = obj.func(a, b[2][1]), arguments); retun true;
// and so on';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php