I need some advice with the following problem. I receive text with the following format:
"text (textInBrackets), text2 (textInBrackets2), text3 (textInBrackets3),..."
Every text and textInBrackets could have letters, numbers and also brackets. The separation between pairs are the commas, the closing bracket near the comma is the one that determines where the right element of the pair ends.
I need to split the text in a way that I could separate every pair of text and textInBrackets and put it in an array like:
String[][] pairs= new String[n][2];
pair[0][0]="text";
pair[0][1]="textInBrackets";
pair[1][0]="text2";
pair[1][1]="textInBrackets2";
Example:
String text="texttext(text)text(subtext), othertext152(de)sert(subothertext), textwithoutbracket, elems(subelem)";
String[][] return=splitFunction(text);
The return array is:
String[][] pairs= new String[n][2];
pair[0][0]="texttext(text)text";
pair[0][1]="subtext";
pair[1][0]="othertext152(de)sert";
pair[1][1]="subothertext";
pair[2][0]="textwithoutbracket";
pair[2][1]=null;
pair[3][0]="elems";
pair[3][1]="subelem";
I already have a solution for the problem but is not bullet proof and it has some bugs.