Essentially, you're looking for every consecutive set of characters that are not square brackets. It doesn't matter what order the brackets are in. So you could quite easily do something like this:
key = "["
+key.replace(/]/g,'[') // replace close brackets with open ones
// (to make them the same symbol)
.replace(/\[+$/,'') // trim off brackets at the end of the string
.replace(/\[+/g,"][") // replace brackets with "][" (separating the words)
+"]";
So for example sample[hard][damn_you[0]]
goes through these steps:
sample[hard][damn_you[0]]
sample[hard[[damn_you[0[[
sample[hard[[damn_you[0
[sample][hard][damn_you][0]