I want to remove what is inside the last bracket of a string.

This is the ids string:

```
rule_Group[0][5]

```

This is my Javascript code

```
var str = 'rule_Group[0][5]';

var a = str.lastIndexOf("[") + 1;
var b = str.lastIndexOf("]") - 1;
var res = str.substr(a,b)

document.write(res)

```

I want to keep the 5 in the brackets. No matter what JS doesn't allow me to cut out just one character. I have even manually tried to do this with no luck.

Any advice?