Select cases from a list
One way is this
ReplaceList[{1, 1, 1, 0, -1, -1, 1, 1, 1, 0, 0, 0, 0, -1, -1},
{___, a : PatternSequence[1, 0 .., -1], ___} :> {a}]
(* {{1, 0, -1}, {1, 0, 0, 0, 0, -1}} *)
If you need the position, length or some other information about the location of the match inside the list, you could do it like this:
ReplaceList[{1, 1, 1, 0, -1, -1, 1, 1, 1, 0, 0, 0, 0, -1, -1},
{s___, a : PatternSequence[1, 0 .., -1], ___} :>
With[{l = Length[{s}]}, {{l + 1, l + Length[{a}]}, {a}}]]
(* {{{3, 5}, {1, 0, -1}}, {{9, 14}, {1, 0, 0, 0, 0, -1}}} *)
This stores the start elements before the matching pattern in s
and you can calculate all information from this. Here, I give the start- and end-position of the pattern inside the list.
Be aware, the method posted by halirutan, while concise, will be glacially slow on larger lists. Here's a method whipped up cigar-thinking that is much faster. Just a WIP, there's probably 2-3X performance improvement left in it (e.g., using something other than membership testing), but again, just barfed this out during leisure time (edit, updated code, much faster, will update timings from older code as patience permits):
getSeq3[list_] :=
Module[{z = Split[Select[Pick[Range@Length@list, list, 0],
1 < # < Length@list &], #2 == #1 + 1 &][[All, {1, -1}]]},
{# + {-1, 1}, list[[#[[1]] - 1 ;; #[[2]] + 1]]} & /@
Select[z, (list[[#[[1]] - 1]] == 1 && list[[#[[2]] + 1]] == -1) &]]
A quick timing comparison (lists generated with RandomInteger[{-1,1},size]
, on a netbook so expect 10-20X faster on "real" machines):
Updated timings from improvements:
An even faster result can be had by moving things into the string domain:
getSeqSP[list_] :=
Module[{sp = StringPosition[FromCharacterCode[list + 2],
FromCharacterCode[3] ~~ Repeated[FromCharacterCode[2], {1, Infinity}] ~~
FromCharacterCode[1]]},
Transpose[{sp, Rest@Extract[list, Prepend[Transpose[{Span @@@ sp}], {{}}]]}]]
Timings are so quick, even on the netbook they are below resolution:
On larger lists, this is order of magnitude + faster than already fast methods above. Probably about as fast as possible without resorting to compiled methods.