我有这个自定义函数and()
和or()
,我需要在这些函数中获取参数:
and(one,two,three) // ["one", "two", "three"]
我正在使用正则表达式和拆分:
var string = 'and(one,two,three)';
var reg = /(and|or)\((.*)\)/g;
var match = reg.exec(string);
var args = match[2].split(','); // ["one", "two", "three"]
但是现在,如果我在函数内部添加另一个函数,就像这样:
and(one,two,or(three,four)) // ["one", "two", "or(three", "four)"]
由于split()
,它拆分了内部函数。
我需要一个正则表达式来返回函数内部的所有参数,如下所示:
and(one,two,or(three,four)) // ["one", "two", "or(three,four)"]
所以我可以分别处理每个参数。谢谢。