I need to support exact phrases (enclosed in quotes) in an otherwise space-separated list of terms. Thus splitting the respective string by the space-character is not sufficient anymore.
Example:
input : 'foo bar 'lorem ipsum' baz' output: ['foo', 'bar', 'lorem ipsum', 'baz']
I wonder whether this could be achieved with a single RegEx, rather than performing complex parsing or split-and-rejoin operations.
Any help would be greatly appreciated!
… returns the array you’re looking for.
Note, however:
replace(/^'([^']+)'$/,'$1')on the results.loremandipsum, they’ll be in the result. You can fix this by runningreplace(/\s+/,' ')on the results.'afteripsum(i.e. an incorrectly-quoted phrase) you’ll end up with:['foo', 'bar', 'lorem', 'ipsum', 'baz']