let reg = /\[([^\[\]]+)\]/g let s = "{[1,[2]2[s],[3,4],'aas]a'}" let result = s.match(reg) console.log(result) // output ['[2]', '[s]', '[3,4]']