var str = "test[0].array[1]"; var out = str.replace(/([^\.]*?)\[(.*?)\]/g,'"$1",$2').replace('.',','); alert(out)