Way to Return The Number of Matches In a String

Having some string manipulation issues here; I’m trying to make a system that takes a string, looks for opening and closing characters, and returns the substring in between those. Seems simple enough; but I want support for nested substrings.

The characters I’m using are these : ‘{ }’

So the string would look like this:

"{Big Open {Little Open {Littler Open Littler Close} Little Close} Big Close}"

So I think it’d be really easy to make a function to return what I want if I could call some sort of function of string, that would tell me how many opening brackets there are in between “{Big Open” and “Littler Close}”. I thought there was already a function for that; but I can’t find it. Does anyone know if there is, or a better way to go about this?

That would involve parsing the string.

Actually I just found that I can use the second return from string.gsub for this;

So now that I know how many Opening brackets there are after “{Big Open” I know how many closing brackets to ‘skip past’ in order to find the true closer being “Big Close}”

1 Like