function extractBracketedContent(text) {
const pattern = /\[(.*?)\]/g;
const matches = [];
let match;
while ((match = pattern.exec(text)) !== null) {
matches.push(match[1]);
}
return matches;
}
const input = "This is a [sample] string with [multiple] square [brackets].";
const extracted = extractBracketedContent(input);
extracted.forEach(item => {
console.log(item);
});
/*
run:
sample
multiple
brackets
*/