tomas
tomas

Reputation: 461

Get substring between tokens

Could you explain how to get the substring between tokens [ and ;

The original string:

a [
    b [
        text1;
        text2;
        c [
            text3;
            text4;
        ]
    ]
]

And that I want:

text1;
text2;
text3;
text4;

Upvotes: 1

Views: 231

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726987

A quick approach would be to search from the back for a ';', then search back for '['starting from that position, and split the resulting string at the semicolons. Repeat the same process until you can no longer find a semicolon ';'.

A better approach would be to write a simple recursive descent parser with a single rule: the detection would be a lot more reliable if errors in the source are present.

Upvotes: 2

Related Questions