JSFiddle - React, Tailwind, and code Playground
by Daedalus
JavaScript
let a = "14.oO({text}),$+(14,$chr(44),15) $+ [{text}],07({text}),06[[{text}]]".split(/,/);
console.clear();
function mapStr(arr) {
let chunks = [];
for (let idx = 0; idx < arr.length; idx++) {
let chunk = arr[idx];
if (/^\$(\w+|\+)\(/.test(chunk)) {
let newArr = arr.slice(idx),
endingIdx = newArr.reduce((acc, elm, nidx) => {
if (elm.indexOf(')') > -1) {
return nidx;
} else {
return acc;
}
}, idx);
chunks.push(arr.slice(idx, endingIdx + 1).join(','));
idx += endingIdx - 1;
} else {
chunks.push(chunk);
}
}
return chunks;
}
console.log(mapStr(a));