So my goal is to be able to use the %b() pattern to get the text between brackets within a string. However, I also need it to ignore any brackets that are inside quotes in that string, and not count them as extra opening/closing brackets. For example:
local str = [[(one(two("three")))]]
print(str:match("%b()")) --> (one(two("three")))
will print normally. But then, if a bracket is added within the quotes in the string, it treats it as a closing bracket, only printing two closing brackets at the end of the string when there should be three:
local str = [[(one(two("thr)ee")))]]
print(str:match("%b()")) --> (one(two("thr)ee"))
Any ideas on how to go about ignoring brackets within quotes in the string?

2 comments
How'd it know where the end is? In the second example, the match has 3 opening parentheses and three closing parentheses. Why'd it capture the third one?
It treated the closing parenthesis inside the string as one, taking away the last parenthesis. Don't need an answer any more though, but it would still be nice to know any simple way to do this.