The following string can be converted easily into a list with ToExpression
string = "{{a},{b,c,d},{e,{f,{g}}}}";
ToExpression@string
However, if the string contains characters that can be misinterpreted as syntax errors, I run in to problems.
string = "{{a},{b,c,d},{e,{[f],{g}}}}"
ToExpression
throws an error since "[f]" isn't valid Wolfram.
(Side note, is that sentence grammatically correct? I would write "...isn't valid Java or C". Is it more appropriate to write "... isn't valid Wolfram Language?")
I would like to convert a string into a nested list of strings.
For reference (2242) starts with data whose Head
is List
and doesn't readily appear to work with nested lists, (43930) is a similar question focusing on Graph
and looks promising except that the solution uses levelspec in Cases
which, to my understanding, is not available in StringCases
.
[f]
to be turned into? Left untouched? $\endgroup$List[List[a],List[b,c,d],List[e,List["[f]",List[g]]]]
as a result? $\endgroup$List[List["a"],List["b","c","d"],List["e",List["[f]",List["g"]]]]
. $\endgroup$