local str = "Extract (a(b)c) and ((d)f(g))";
for s in string.gmatch(str, "%b()") do print(s) end
local str2 = "Extract [a[b]c] and [[d]f[g]]";
for s in string.gmatch(str2, "%b[]") do print(s) end
local str3 = "Extract {a{b}c} and {{d}f{g}}";
for s in string.gmatch(str2, "%b{}") do print(s) end
bG9jYWwgc3RyID0gIkV4dHJhY3QgKGEoYiljKSBhbmQgKChkKWYoZykpIjsKZm9yIHMgaW4gc3RyaW5nLmdtYXRjaChzdHIsICIlYigpIikgZG8gcHJpbnQocykgZW5kCmxvY2FsIHN0cjIgPSAiRXh0cmFjdCBbYVtiXWNdIGFuZCBbW2RdZltnXV0iOwpmb3IgcyBpbiBzdHJpbmcuZ21hdGNoKHN0cjIsICIlYltdIikgZG8gcHJpbnQocykgZW5kCmxvY2FsIHN0cjMgPSAiRXh0cmFjdCB7YXtifWN9IGFuZCB7e2R9ZntnfX0iOwpmb3IgcyBpbiBzdHJpbmcuZ21hdGNoKHN0cjIsICIlYnt9IikgZG8gcHJpbnQocykgZW5k