Suppose I have a list of arbitrary length:
{1, 2, 3, "Open", 3, 2, "Close", 9, 3, 4, "Open", 1, 0, "Close", 3, 5}
and I am trying to extract the sequences delimited by the "Open"/"Close" tags, i.e. the answer I want is:
{{3, 2}, {1, 0}}
What's the right way to do this? The data I am actually working with is a large XML document and I am trying to extract sections of it by identifying certain tags as boundaries. I've fiddled with different pattern matching functions but can't figure out how to operate on a list in this way since I am trying to match patterns on an intermediate level between individual elements and the entire list.
EDIT
To clarify, I don't know in advance how many such sequences the data will contain or how many elements will be present between any particular set of tags.
Take[list, #] & /@ (Partition[ Flatten[Position[list, "Open" | "Close"]], 2] /. {a_?NumberQ, b_?NumberQ} -> {a + 1, b - 1})
$\endgroup$