javascript - 如何使 rex to [ ] 替换或拆分?
问题描述
我将此字符串“root [0] [1] [2]”作为rex。我想要这个字符串数组([root, 0, 1, 2])或字符串(root.0.1.2)。
我试过 make /["["]|["]["]/g. 但是,这个 rex ][ 字符串承认包含 ["]。这个 rex ["["][^"["]* 识别了整个括号。
/["["]|["]["]/g <- 1
或者
/["["][^"["]*/g <- 2
结果2:root[0][1][2][3] => [0],[1],[2],[3]
结果 1:["]["] => 错误
解决方案
匹配除负字符集[
以外的任何内容:]
const str = 'root[0][1][2]';
const matches = str.match(/[^[\]]+/g);
console.log(matches);
推荐阅读
- java - 更改 shared_ptr 的 getCPtr() 可见性
- ruby-on-rails - 乘客卡在 AppPreloader 分叉上,100 cpu 使用率
- python-3.x - 清理json数据
- java - 如何使用 java 从 Gitlab 帐户下载文件
- visual-studio-code - VSCode 1.37.1 中值“selectNextQuickFix”和“selectPrevQuickFix”的等价物是什么?
- python-3.x - 创建相互排斥的个人群体(集群)的逻辑
- javascript - 此代码片段中的“模型”类的意图是什么?
- git - 如何提交 Git 钩子?
- python - 我无法通过“列表索引超出范围”错误消息
- xamarin.forms - 如何在 mmvmcross 中将值转换器与 rio 绑定结合使用?