var testString = 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.\nDt."\n57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019';
var newLine = testString.split('\n');
Oputput of the newLine
[ 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.','Dt."','57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019' ]
在这里,我想避免\n
为"Order Comp.\nDt."
的字符串形式
[ 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.\nDt."','57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019' ]
答案 0 :(得分:1)
然后而不是分割字符串,为什么不匹配要保留的部分?
var testString = 'Sr No\tMonth\tMill\tOrigin\tParty\tOrder Date\t"Order Comp.\nDt."\n57\tJan-19\tGINZA\tIND\tSBL\t28.01.2019\t10.02.2019';
var out = testString.match(/(?:"[^"]*"|[^\n])+/g);
console.log(out);