JS:
const [ , path, file ] = /(.+\/)([^\/]+)$/.exec(str);
// или
const i = str.lastIndexOf('/') + 1;
const file = str.slice(i);
const path = str.slice(0, i);
// или
const parts = str.split(/(\/)/);
const file = parts.pop();
const path = parts.join('');
PHP:
preg_match('~^(.+\/)([^\/]+)$~', $str, $matches);
list($path, $file) = array_slice($matches, 1);
// или
$i = strrpos($str, '/') + 1;
$file = substr($str, $i);
$path = substr($str, 0, $i);
// или
$parts = preg_split('~(?<=\/)~', $str);
$file = array_pop($parts);
$path = implode('', $parts);