Question: I have a path and I am trying to pop off everything after the last /, so 'folder' in this case, leaving the newpath as C://local/drive/folder/.

I tried to pop off the last / using pop(), but can't get the first part of the path to be the new path:

```
var path = C://local/drive/folder/folder
var newpath = path.split("/").pop();
var newpath = newpath[0]; //should be C://local/drive/folder/

```

How can I accomplish this?

Answer: 
Could also use a regex:

```
function stripLastPiece(path) {
    var matches = path.match(/^(.*\/)[^\/]+$/);
    if (matches) {
        return(matches[1]);
    }
    return(path);
}

```

Working example: <http://jsfiddle.net/jfriend00/av7Mn/>
```
var foo = "C://local/drive/folder/folder";
foo.match(/(.+\/)[^\/]+$/);

```

would result in: `["C://local/drive/folder/folder", "C://local/drive/folder/"]`

though i would prefer user1689607's answer