gives a list of the sublists in list that match the pattern patt in any order.


gives a list of the values of rhs corresponding to matching sublists.


includes only the first n matches.

Details and Options


open allclose all

Basic Examples  (1)

Find sublists that match a pattern:

Perform a replacement on each match:

Scope  (3)

Find subsets of variable length:

Combine a variable-length and a fixed-length pattern:

For a variable-length pattern, SubsetCases returns the longest match:

With OverlapsTrue, all possible matches are returned in order of decreasing length:

SubsetCases tries different branches of Alternatives (|) until one matches:

A different order of the pattern produces a different result:

Options  (1)

Overlaps  (1)

Allow overlaps:

Allow no overlaps:

Applications  (2)

Find triangles in a directed graph:

Highlight the triangles:

Find cycles of length four in an undirected graph:

Highlight the cycles:

Properties & Relations  (3)

The order of elements in each result is determined by the pattern:

Verify that each result matches the pattern:

Choose a different order of pattern and result:

Find all subset positions including overlaps:

Extract the subsets:

The result is equivalent to that of SubsetCases:

Find all subsets:

Find the same result using Subsets:

Introduced in 2020