I'm working with a structure that consists of either a single string array ['stufff sjktasjtjser ((matchthis))'], or the same structure in a nested array ['stufff', ['more stuff ((matchhere))'], '((andanother))']. I have the ability to loop through and match all regex patterns within the brackets, as well as replace the text:
// After flattening the array, let's focus on the first element and assume I am looping within it.
var matches = currentArrayElement.matchAll('fancyregex') // pretending to match the brackets
matches.forEach(match=>currentArrayElement=currentArrayElement.replaceAll(match[0],'whatwhat'))
console.log(currentArrayElement) //'stufff sjktasjtjser whatwhat'
// However, my desired output is actually:
// currentArrayElement = ['stufff sjktasjtjser','whatwhat'];
Can anyone provide guidance on how I can achieve this? Or suggest any template library that can handle this requirement for nested arrays? Sometimes I need to output an array of strings ['tss'], and other times an array with objects [{}].
Thank you.