The path from which I want to extract the filename takes the form:

```
C:\Folder1\Folder2\Folder3\Folder4\Folder5\x.png

```

This should give x (I do not need the extension). The file is always a PNG file. x can be 1, 2, 3 or 4 digits, but can never contain any other character (only a number).

I tried a 'manual' method, which is working well.

```
function getId(x) {
  x = x.slice(0,-4);
  var str = "";
  var flag = 0;
  for(var i = x.length - 1; i >= 0; i--) {
    if(!isNaN(x[i])) {
      str = x[i] + str;
      flag = 1;
    } else if(flag == 1) {
      break;
    }
  }
  console.log(str);
}

```

Is there any simpler approach without using a library?