javascript - 获取自定义函数参数的正则表达式
问题描述
我有这个自定义函数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)"]
所以我可以分别处理每个参数。谢谢。
解决方案
推荐阅读
- android - 在不同的国家推出不同的版本
- php - 如何在php中为数组编写foreach循环
- javascript - 如何在 Javascript 中使用变量创建 JSON?
- ios - UIUserInterfaceStyle 键在 Xcode 12 的 Info.plist 中不可用,如何从 Info.plist 禁用 Xcode 12 中的暗模式?
- c++ - 通过将值从 int 更改为 float,总值会发生变化 谁能解释为什么?请
- react-testing-library - 如何组合复杂的选择器
- powershell - 无法从 Internet 加载自定义 PowerShell 脚本
- android - null 不能转换为非 null 类型 kotlin.collections.List
- javascript - 单击复选框并将所有内容保存到本地存储时检查以前的复选框
- python - 按列分组,对另一列进行排序并为python中的行分配排名