进程字符串在单独的行上的嵌套方括号内逐行阻塞

I am not a php expert by any means but am able to accomplish some very useful things writing code that runs on a local server to process large text blocks.

I am really stuck on one project right now. I am trying to convert an application file format from a new version to an older version. The program doesn't have a "save as" to an older version. The file format is plain ascii text making it very simple to work with. The code uses square brackets with tab indents for formatting.

I am using a simple web form, pasting in the file text, and then processing and printing to the screen via echo in a pre wrapper. I then copy that text to a new file in a text editor, save it with the correct app extension and open it.

Here is where I run in to trouble. The majority of the text is inside square brackets. In some areas there are nested square brackets. Within the brackets each line may be in a different format or structure. It's all "the same". Meaning the patterns are always the same based on the line just before a bracket but it's tricky to get my head around it. For example below the "keys X" block requires that the 4th item from the end be removed (easy to do using space as a delimiter).

    mesh
[
    curve_interpretation 1
    points 10
        [
            keys 1
                0 1 0.1 0.5 1 0 0 0 0.527883 -0.776941
        ]
        [
            keys 1
                0 1 0.1 0.5 1 0 0 0 1
        ]
        -2
        true
        1
            0 0 
        [
            keys 1
                0 1 0.1 0.5 1 0 0 0 0.279041 -0.16504
        ]
]

I've got a ton of this working properly. My first attempt simply uses basic regex and preg_match to find and replace single lines without or not within brackets and then explode based on the brackets, use a foreach loop, then exploding again by line for each bracketed block string to examine and format each line within the brackets. I was trying to use variables to toggle bracket states and simply echoing the brackets back in.

Sample of my code:

        $arr = preg_split("/(\t+\\]\t+\\\t+[|\\\t+[|\\\t+])/", $_POST['formtext'], -1, PREG_SPLIT_NO_EMPTY);
    echo '<pre>';
    foreach ($arr as $block) {
        foreach(explode("
", $block) as $line) {
            do stuff here
            echo the text back in
        }
    }

I am having issues with doing stuff line by line and not knowing which type of block I am processing. The brackets are on their own line and I keep running in to problems trying to "tag" one block as different from another based on a previous line that matched a regex search, and continuing until that block is done and toggling back to a different looping search.

I searched and searched for various regex solutions for extracting these types of strings, but in the examples I could find the brackets aren't on a separate line and it's tricky to do the nested processing.