I'm trying to get an array of arguments from a string by doing the following
const str = `argument "second argument" 'third argument' \`fourth argument\``;
str.split(/\s(?=(?:[^'"`]*(['"`])[^'"`]*\1)*[^'"`]*$)/g);
The expected output:
['argument', '"second argument"', "'third argument'", '`fourth argument`']
But this comes out:
['argument', '`', '"second argument"', '`', "'third argument'", '`', '`fourth argument`']
How can I get back an array of just 4 elements?