"a,b",a b,,,,,,,,,,,,,,,,,,,,
split("\r\n")
а затем разбиваю по клеткам используя split(",")
a b
"a,b"
"a,b"
игнорировалась.function CSVToArray(strData, strDelimiter = ','){
const objPattern = new RegExp(
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
"([^\"\\" + strDelimiter + "\\r\\n]*))",
'gi'
);
const arrData = [[]];
let arrMatches = null;
while (arrMatches = objPattern.exec(strData)){
const strMatchedDelimiter = arrMatches[ 1 ];
if (
strMatchedDelimiter.length &&
strMatchedDelimiter !== strDelimiter
) {
arrData.push([]);
}
const strMatchedValue = arrMatches[2]
? arrMatches[2].replace(new RegExp("\"\"", 'g' ), "\"")
: arrMatches[3];
arrData[arrData.length - 1].push(strMatchedValue);
}
return( arrData );
}
console.log(CSVToArray('"a,b",a b,')); // Array(3) [ "a,b", "a b", "" ]
const string = "a,b",a b,,,,,,,,,,,,,,,,,,,
const cells = string.split(/,(?!\s*")/);
console.log(cells);
////
[
"a,b",
"a b",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
]