JQuery/JavaScript Split String By Commas That Are Outside Of Parenthesis
I am using jQuery & JavaScript!! I have a string, for example 'cubic-bezier(0.25, 0, 0.25, 1), ease-in, ease-out, linear' ..and I want to split it into this array: // (the fo
Solution 1:
Match any comma not inside parentheses
var myString = "cubic-bezier(0.25, 0, 0.25, 1), ease-in, ease-out, linear";
var parts = myString.split(/\,\s?(?![^\(]*\))/);
console.log(parts)
/\,\s?(?![^\(]*\))/
\,
matches the character,
literally\s?
matches any whitespace character. The?
quantifier matches between zero and one times(?![^\(]*\))
Negative Lookahead asserts that the regex does not match a single character not present in the list below[^\(]
Quantifier. Matches between zero and unlimited times, as many times as possible\(
matches the character(
literally\)
matches the character)
literally
Post a Comment for "JQuery/JavaScript Split String By Commas That Are Outside Of Parenthesis"