【发布时间】:2017-06-01 02:36:08
【问题描述】:
基本上我想把数组从
["{ test1, test2 }", "test3", "{test4, test5}"]
到
["test1","test2","test3","test4","test5"]
我正在使用正则表达式,matchTest 是保存正则表达式的变量,用于匹配单词并使用匹配项填充此数组,并将数组固定在同一循环中。
while (regexMatches = matchTest.exec(sourceCode)) {
testArray.push(regexMatches[1].replace(/\W/g, " ").split(" "));
testArray = [].concat(...testArray);
testArray = testArray.filter(testArray => testArray != '');
}
我这样做的方式很有效,但看起来很混乱。任何有关如何改进这一点的帮助将不胜感激。
【问题讨论】:
标签: javascript arrays regex