I need to split a command string either on a space or if a substring is surrounded by double quotes. So an example input would be:
'ADD PRODUCT "This could be any number of words" 232323-fwe4f434-354trcc2'
With that as in input im looking for an output of:
['ADD', 'PRODUCT', '"This could be any number of words"', '232323-fwe4f434-354trcc2']
Ive tried this and it gets me close but still not quite what i need
input:
const str = 'ADD PRODUCT "This could be any number of words" 232323-fwe4f434-354trcc2'
console.log(str.split(/\s*(")\s*/))
output:
[
'ADD PRODUCT',
'"',
'This could be any number of words',
'"',
'232323-fwe4f434-354trcc2'
]