I currently have this regular expression to split strings by all whitespace, unless it's in a quoted segment:
keywords = 'pop rock "hard rock"';
keywords = keywords.match(/\w+|"[^"]+"/g);
console.log(keywords); // [pop, rock, "hard rock"]
However, I also want it to be possible to have quotes in keywords, like this:
keywords = 'pop rock "hard rock" "\"dream\" pop"';
This should return
[pop, rock, "hard rock", "\"dream\" pop"]
What's the easiest way to achieve this?