Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I ignore brackets within quotes?

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

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?

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.

1 answer

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

local str = '(one(two("thr)ee")))'

3 comments

0

It still makes a string...

0

You said you wanted a string?

0

But the way the person made a string is still correct, though.

This discussion is preserved as it was. New answers, comments, and votes are closed.