正则表达式以获取自定义函数的参数

时间:2019-02-05 14:45:18

标签: javascript regex

我有这个自定义函数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)"]

所以我可以分别处理每个参数。谢谢。

0 个答案:

没有答案
相关问题