This is ugly, but if you donโt have \ "inside your quoted strings (this means you donโt have lines that look like this (" foo bar \ "badoo \" goo "), you can split it into" first ", and then suppose all of your even elements in the array are, in fact, strings (and break the odd numbered elements into their component parts on the token).
If you have * in your lines, you need to first convert them to another temporary token, which you will convert later after your operation.
Here is the violin ...
http://jsfiddle.net/VW9an/
var str = 'abc;def;ghi"some other dogs say \\"bow; wow; wow\\". yes they do!"and another; and a fifth' var strCp = str.replace(/\\"/g,"--##--"); var parts = strCp.split(/"/); var allPieces = new Array(); for(var i in parts){ if(i % 2 == 0){ var innerParts = parts[i].split(/\;/) for(var j in innerParts) allPieces.push(innerParts[j]) } else{ allPieces.push('"' + parts[i] +'"') } } for(var a in allPieces){ allPieces[a] = allPieces[a].replace(/--##--/g,'\\"'); } console.log(allPieces)
source share