I would like to parse a string like: foo, bar, baz, "hello, world" to output:
["foo", "bar", "baz", "hello, world"]
I would like to parse a string like: foo, bar, baz, "hello, world" to output:
["foo", "bar", "baz", "hello, world"]
Just use |
var regex = /"([^"]*)"|'([^']*)'|[^\s,]+/g;
var text = "Hello world \"Boston Red Sox\" hello, world, \'boston, red sox\', \'beached whale\', pickup sticks";
var output = [];
var m;
while ((m = regex.exec(text)) !== null)
{
output.push(m[1] || m[2] || m[0]);
}
console.log(output);