const str1 = '2[a]1[bc]'; // aabc
const str2 = '2[e2[d]]'; // eddedd
const str3 = '3[abc]2[e2[d]]ff'; // abcabcabccdcdff
const str4 = 'abc13[cd]2[ee]ff'; // abccdcdcdeeff
function decodeStr(str) {
let r = str.replace(/(d*)[([^[|]]+)]/g, ($1, $2,$3) => {
let s=''
$2 = $2 || 1
for (let i = 0; i < $2; i++){
s += $3
}
return s
})
return /[.*]/.test(r) ? decodeStr(r) : r
}