I admit it, I used ChatGPT, but it was very straight forward so decided to reply with it anyway:
function fetchBracketText(str: string): {string}
local texts = {}
for text in str:gmatch("%[(.-)%]") do
table.insert(texts, text)
end
return texts
end
local texts = fetchBracketText("this [is] a [test]")
print(texts) --{"is", "test"}