Have a look at split and join
This assumes positioning is always the same.
Or if it not you can always split by '][', resplit the first item in your split array and see how many items are in it.
In other words break up your problem into smaller chunks.