3 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
,(?=(?:[^"]*"[^"]*")*[^"]*$)
或
"[^"]*"(*SKIP)(*F)|,
"[^"]*"
buz,"bar,foo"
"bar,foo"
(*SKIP)(*F)
|
,
|
buz
,(?!(?:[^"]*"[^"]*")*[^"]*$)

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
function splitNotStrings(str){ var parse=[], inString=false, escape=0, end=0 for(var i=0, c; c=str[i]; i++){ // looping over the characters in str if(c==='\\'){ escape^=1; continue} // 1 when odd number of consecutive \ if(c===','){ if(!inString){ parse.push(str.slice(end, i)) end=i+1 } } else if(splitNotStrings.quotes.indexOf(c)>-1 && !escape){ if(c===inString) inString=false else if(!inString) inString=c } escape=0 } // now we finished parsing, strings should be closed if(inString) throw SyntaxError('expected matching '+inString) if(end<i) parse.push(str.slice(end, i)) return parse}splitNotStrings.quotes="'\"" // add other (symmetrical) quotes here
- 3 回答
- 0 關(guān)注
- 673 瀏覽
添加回答
舉報(bào)