I have a nested list similar to this example list (but much bigger and more messy):
str = {{{"a a-a", "a a-b", "a a-c", "a a-d"},
{"a b-a", "a b-b", "a b-c", "a b-d"}},
{{"b a-a", "b a-b", "b a-c", "b a-d"},
{"b b-a", "b b-b", "b b-c", "b b-d"}}};
I am trying to selectively to remove most of the entries whilst keeping the "...-c" entries within the nested structure so that I end up with something like this:
cstr = {{{"a a-c"}, {"a b-c"}}, {{"b b-c"}, {"b b-c"}}};
or at least this:
cstrflat = {{"a a-c", "a b-c"}, {"b b-c", "b b-c"}};
I can find the positions of the desired entries with:
Position[Map[StringMatchQ[#, ___ ~~ "-c"] &, str, {3}], True]
{{1, 1, 3}, {1, 2, 3}, {2, 1, 3}, {2, 2, 3}}
or use Cases to get a flattened list with:
Cases[str, _?(StringMatchQ[#, ___ ~~ "-c"] &), {3}]
{"a a-c", "a b-c", "b a-c", "b b-c"}
but, I can't work out how to thin-out the existing nested list structure. I think it might be possible with Select but my attempts so far haven't worked.
Any suggestions? Are there other ways to do this sort of thing?
/;! StringMatchQ.... Many thanks! – geordie May 30 '13 at 04:47