我用这个字符串"root2“做rex。我需要这个字符串数组(根,0,1,2)或字符串(root.0.1.2)。
我尝试了make /[“x”/g。但是,这个rex ][字符串认知为包含“。这个rex [“^”*识别整个括号。
//[/g <- 1]
或
/[“^”*/g <- 2
结果2: root2 => ,1,2,3
结果1:“=>错误”
发布于 2019-06-22 04:16:08
将除[或]之外的任何内容与负号字符集匹配:
const str = 'root[0][1][2]';
const matches = str.match(/[^[\]]+/g);
console.log(matches);
https://stackoverflow.com/questions/56712532
复制相似问题