My goal is to transform the array from
["{ test1, test2 }", "test3", "{test4, test5}"]
into
["test1","test2","test3","test4","test5"]
Using regex and a variable called matchTest to match words and populate an array with the matches. In the same loop, I am also correcting the structure of the array.
while (regexMatches = matchTest.exec(sourceCode)) {
testArray.push(regexMatches[1].replace(/\W/g, " ").split(" "));
testArray = [].concat(...testArray);
testArray = testArray.filter(testArray => testArray != '');
}
The current method is functional, but it appears somewhat messy. Any suggestions on how to streamline this process would be greatly appreciated.