# Parsing string with nested information

I am trying to parse a string, but I have no idea how to solve the following problem

problem = "a { b { c d } e } aa { bb cc }";
answer = {{"a", "b", "c"}, {"a", "b", "d"}, {"a", "e"}, {"aa", "bb"}, {"aa", "cc"}};


So the answer is a path in each sub-list of the list

Any suggestions ?

• can you please enter the problem is Mathematica synatx? Is the problem meant to be: problem = a { b { c d } e } a a { b b c c } ? I do not understand what path node list of the tree information here. You mean TreeForm ? can you give a link that explains what it is? – Nasser Jan 17 '15 at 9:02
• now modified. sorry for ambiguity. – marsiano Jan 17 '15 at 9:08

I may have misunderstood the requirement but this seems to work for the example at least:

problem = "a { b { c d } e } aa { bb cc }";

Map[Flatten, StringSplit[problem] //.
{head___, x_, "{", Shortest[y__], "}", tail___} :>

(* {{"a", "b", "c"}, {"a", "b", "d"}, {"a", "e"}, {"aa", "bb"}, {"aa", "cc"}} *)

• Thanks Woods. I think you gave me a correct answer! – marsiano Jan 19 '15 at 2:34
• some explanation would have been helpful. – törzsmókus Dec 12 '18 at 21:10