Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How would I ignore brackets within quotes?

Asked by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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?

0
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? hiimgoodpack 2009 — 6y
0
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. mattscy 3725 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

Try formatting the string using the ' ' marks, like this?

local str = '(one(two("thr)ee")))'
0
It still makes a string... hiimgoodpack 2009 — 6y
0
You said you wanted a string? User#20158 0 — 6y
0
But the way the person made a string is still correct, though. hiimgoodpack 2009 — 6y
Ad

Answer this question