2[3[a]b] in aaabaaab konvertieren

Few days ago one of the member of our telegram group aked how to convert 2[3[a]b] to aaabaaab, 2[a]3[b]c to aabbbc and so on.

Question and decision how to solve the task

  1. How can we seperate the right opening and closing bracket including the number infront
    • This can be done with the simple regex (\d{0,})\[([^\[\]]+)\]

Solution

I implemented the logic in a class. I implemented the Unit Test to the class too, so that the logic will still work correct when making changes to it.

Unit Test

For the Unit Test I have created three methods with different bracket combinations, from simple to very deep.

And this is the result of the Unit Test.

Get the source code from GitHub

Download

You can download the soure code from GitHub. Available Versions are:

Import using abapGit

Or you can import the source code directly into your system by using abapGit. You can find more information about how to import repo from GiHub here.

Copy the repo link https://github.com/stekoester/convert_bracketstring_2_string.