JSFiddle - React, Tailwind, and code Playground
JavaScript
var s = "this is a [sample] string with [some] special words. [another one]";
var matches = [];
var pattern = /\[(.*?)\]/g;
var match;
while ((match = pattern.exec(s)) != null)
{
matches.push(match[1]);
}
alert(matches);