Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

SequenceCases

SequenceCases[list,patt]
gives a list of the sublists in list that match the sequence pattern patt.

SequenceCases[list,pattrhs]
gives a list of the values of rhs corresponding to sublists that match patt.

SequenceCases[list,patt,n]
includes only the first n matches.

Details and OptionsDetails and Options

  • In SequenceCases[list,patt], patt can be an expression with head List that includes pattern constructs such as PatternSequence, Repeated (..), Blank (_), and BlankSequence (__).
  • The pattern patt can also be a pattern that matches a list but does not itself have head List.
  • With the default option setting OverlapsFalse, SequenceCases includes only sublists that do not overlap. With the setting OverlapsTrue, it includes sublists that overlap.
  • With Overlaps->All, multiple sublists that match the same pattern are all included. With Overlaps->True, only the first such matching sublist at a given position is included.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Find sublists that match a pattern:

In[1]:=
Click for copyable input
Out[1]=

Perform a replacement on each match:

In[2]:=
Click for copyable input
Out[2]=

Count the length of all contiguous sequences of b:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2015
(10.1)