So I have this string:
apple;banana;orange, kiwi;onion,strawberry, avocado
the above string should split into:
apple
banana
orange, kiwi
onion
strawberry
avocado
I found a regex function but it only splits the double quotes " "
str.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
I tried to replace " " with ; ;
str.split(",(?=(?:[^\;]*\;[^\;]*\;)*[^\;]*$)");
but it does't work when I replaced with ;
You could just split by semicolon or by comma, if semicolon is not following.
var string = 'apple;banana;orange, kiwi;onion,strawberry, avocado',
array = string.split(/;\s*|,\s*(?!.*;)/);
console.log(array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With