You don’t need a single big regex to capture everything at once – instead, you can split the problem into two steps. First, match the leading word before the brackets, then use a global regex like /\[(.*?)\]/g
to repeatedly extract the contents inside each pair of square brackets. In JavaScript, that means you can grab the base with something like str.match(/^[^\[]+/)
and then loop over str.matchAll(/\[(.*?)\]/g)
to collect all the bracketed parts. This way you’ll end up with an array like ['something', 'one', 'two']
without trying to force all the groups into one complicated regex .