The last of this series, an elaboration of a question from yesterday:
I'd like to go from:
startList = {"a-1","a","Z","c","d","e","f","g","Z","a","r","s","a-2",
"q","a","Z","c","d","e","f","a-2","m","Z","p","q","r"}
to:
endList = {{"a-1","a","Z","c","d"},{"a-1","g","Z","a","r"},
{"a-2","a","Z","c","d"},{"a-2","m","Z","p","q"}}
So, we make a sublist consisting of one element before "Z", "Z" itself, and the next two elements after each "Z". Then prefix "a-1" in front of each of these sublists, until "a-2" is encountered, at which point "a-2" is prefixed in front of each succeeding sublist, etc.
(The "a-1", "a-2", "a-3" etc. elements can be identified by StringContainsQ[element,"-"], none of the other string elements contain "-".)
Again thanks for your comments.