I have some auto-generated text that includes substrings inside '[]'.

For example:

```
data[0]['x'][1]['y']

```

I want to get rid of the last sub-string.

Output:

```
data[0]['x'][1]

```

Any ideas?