79761513

Date: 2025-09-11 05:54:32
Score: 0.5
Natty:
Report link

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 .

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: Dharm