I have the following list:
lst = {
"str 1,1",
{"str 1,2,1", "str 1,2,2"},
{
(* Inner list 1 *)
{"str 2,1", {"str 2,2,1"}, {{"str 3,1", {"str 3,2,1", "str 3,2,2"}, {}}}},
(* Inner list 2 *)
{"str 4,1", {"str 4,2,1"}, {{"str 5,1", {"str 5,2,1", "str 5,2,2"}, {"str 5,3"}}}},
(* Inner list 3 *)
{"str 6,1", {"str 6,2,1", "str 6,2,2"}, {}}
}
};
The list lst is a three-element list, and is intended to have the following structure: the first element is a string; the second element is a list of strings, possibly empty; the third element is either the empty list, or a list of strings, or a list whose members have the same recursive structure as lst.
I have constructed the following pattern guard for lst:
ptn = {_String, {___String}, {___String} | (a_ /; MatchQ[a, {ptn..}])};
This guard works when the third element of lst contains any one of the three inner lists shown. It also works when the third element of lst contains Inner list 1 and Inner list 3, or Inner list 2 and Inner list 3, but not when it contains Inner list 1 and Inner list 2.
Can you please correct the pattern guard?
ptn = {_String, {___String}, a_ /; MatchQ[a, {___String} | {ptn..}]}but to no effect. – Shredderroy Feb 23 '16 at 21:13