📜  拆分除引号以外的空格 javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:15.604000             🧑  作者: Mango

代码示例1
// Hard to read, but works
// If you want to keep the \ in the string, replace the: c.replace(/\\(.)/,"$1"); by: c;

keywords.match(/\\?.|^$/g).reduce((p, c) => {
        if(c === '"'){
            p.quote ^= 1;
        }else if(!p.quote && c === ' '){
            p.a.push('');
        }else{
            p.a[p.a.length-1] += c.replace(/\\(.)/,"$1");
        }
        return  p;
    }, {a: ['']}).a