preg_match('#^(.*)/[^/]*$#', $string, $match)
matches everything up to but not including the last / and stashes it in $match[1]. If you want to go further back, i.e. n slashes instead of just 1:
preg_match('#^(.*)(?:/[^/]*){[i]n[/i]}$#', $string, $match)
Needless to say, if there aren't any (or enough) slashes, there won't be a match.