im new to regular expressions and i want to build an expression that finds the below pattern:
I have the string:
"'Hello world',dude, 'Somethings, never, turn and go', bye"
I want a regular expression that gives this result:
['Hello world',dude,'Somethings, never, turn and go',bye]
Basically, splitting the string on comma but keeping the phrases with quotes that have comma as a whole.
I have this regex:
let s = "'Hello world',dude, 'Somethings, never, turn and go', bye";
let arr = s.split(/(?<=')\s*,\s*|\s*,\s*(?=')/g);
console.log(arr)
If i add this string "'Hello world',dude, Somethings, never, turn and go, bye"
it gives this result ["'Hello world'", 'dude, Somethings, never, turn and go, bye']
which is wrong. It doesnt split the other values separated by comma. How do i fix that?