首页 > 解决方案 > 获取自定义函数参数的正则表达式

问题描述

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

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

标签: javascriptregex

解决方案


推荐阅读