JSFiddle - React, Tailwind, and code Playground

JavaScript

var texto = "Eu quero comprar [qtdOvos] e [qtdFrutas] somando o total de [totalCompras]";
var arrayStrings = texto.match(/(\[\w+\])/g);
alert(JSON.stringify(arrayStrings, null, 2));