I have a string that I want to split into an array by using the commas as delimiters. I do not want the portions of the string that is between parentheses to be split thoug
You don't need fancy regular expressions for this.
s="bibendum, morbi, non, quam (nec, dui, luctus), rutrum, nulla"
var current='';
var parenthesis=0;
for(var i=0, l=s.length; i 0){
parenthesis--;
current=current+')';
}else if(s[i] ===',' && parenthesis == 0){
console.log(current);current=''
}else{
current=current+s[i];
}
}
if(current !== ''){
console.log(current);
}
Change console.log for an array concatenation or what ever you want.