【发布时间】:2014-03-26 16:02:01
【问题描述】:
我想在 javascript 中使用正则表达式匹配 [] 括号中包含的所有值。
我有以下字符串:[parent][0][child]
尝试使用正则表达式值:\[[^]]*\]
在Rexex Tester 中输入这两个值会成功匹配所有内容,但是当我实际实现它时,match 只返回一个数组键值。
JS 代码:
var string = '[parent][0][child]';
regex = /\[[^]]*\]/;
match = string.match(regex); //Returns just [0]?
我希望 match 返回一个包含所有匹配值 [parent, 0, child] 的数组
【问题讨论】:
标签: javascript regex