【发布时间】:2021-12-20 11:17:16
【问题描述】:
我正在尝试通过执行以下操作从字符串中获取参数数组
const str = `argument "second argument" 'third argument' \`fourth argument\``;
str.split(/\s(?=(?:[^'"`]*(['"`])[^'"`]*\1)*[^'"`]*$)/g);
预期输出:
['argument', '"second argument"', "'third argument'", '`fourth argument`']
但是结果出来了:
['argument', '`', '"second argument"', '`', "'third argument'", '`', '`fourth argument`']
我怎样才能取回一个只有 4 个元素的数组?
【问题讨论】:
标签: javascript regex