SequencePosition

SequencePosition[list,sublist]

gives a list of the starting and ending positions at which sublist appears in list.

SequencePosition[list,patt]

gives all positions at which sequences matching patt occur in list.

SequencePosition[list,patt,n]

includes only the first n occurrences of patt.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Find the positions of a sublist in a list:

Find the positions of all contiguous occurrences of b:

Scope  (5)

Find sequences of integers in a list:

Check the result:

Find sequences of words in a list:

Find sequences of elements that match a pattern, here giving twin primes:

Find sequences in the first 10 million digits of Pi:

Find all overlapping sequences in a list:

Options  (2)

Overlaps  (2)

Allow overlaps:

Allow no overlaps:

Allow overlaps starting at different positions:

Allow no overlaps:

Allow all overlaps:

Properties & Relations  (3)

Find the position of a sequence:

Find the actual sequence:

Find the number of cases:

Replace the sequence by an expression:

For lists of characters, SequencePosition is very similar to StringPosition:

SubsetPosition matches the elements of the sequence in any order:

SequencePosition matches the sequence only in the specified order:

Introduced in 2015
 (10.1)