Unpack a string into an expanded string

represents a sequence of numbers. There can be any number of combinations of semicolons and colons within the brace.

I want to expand it such that these are the results of expanding the two examples above:

"a{1;4:6}"

= "a1a4a5a6"

"a{1;2}b{2:4}" = "a1b2b3b4a2b2b3b4"

I've never had to deal with something like this before, since I am usually given strings in some sort of ready-made format which is easily parsable. In this case I have to parse the string manually.

My attempt is to split the string manually, over and over again, until you hit a case where there is either a colon or a semicolon, then start building the string from there. This is horribly inefficient, and I would appreciate any thoughts on this approach. Here is essentially what the code looks like (I omitted a lot of it, just to get the point across more quickly):

# ... etc, then build up the strings manually once the ranges are figured out.

The thinking behind splitting at the close brace at first is that it is guaranteed that a new identifier, with an associated range comes up after it. Where am I going wrong? My approach works for simple strings such as the first example, but it doesn't for the second example. Furthermore it is inefficient. I would be thankful for any input on this problem.