1

I have this custom functions and() and or(), and I need to get the arguments inside those functions:

and(one,two,three) // ["one", "two", "three"]

I'm doing it with regex and split:

var string = 'and(one,two,three)';
var reg = /(and|or)\((.*)\)/g;
var match = reg.exec(string);
var args = match[2].split(','); // ["one", "two", "three"]

But now if I add another function inside the function, like this:

and(one,two,or(three,four)) // ["one", "two", "or(three", "four)"]

It splits the inside function, because of the split().

I need a regex that returns all the arguments inside the function like this:

and(one,two,or(three,four)) // ["one", "two", "or(three,four)"]

So I can work with each argument separately. Thanks.

JCAguilera
  • 944
  • 1
  • 13
  • 32

0 Answers0