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.
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
- In SequencePosition[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 Overlaps->True, SequencePosition includes sublists that overlap. With the setting Overlaps->False, such sublists are excluded.
- 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.
Examples
open all close allBasic Examples (2)
Find the positions of a sublist in a list:
SequencePosition[{a, b, c, d}, {b, c}]SequencePosition[{a, b, a, b, a, b}, {a, b}]Find the positions of all contiguous occurrences of b:
SequencePosition[{a, b, b, a, b, b, b}, {Repeated[b]}]Scope (5)
Find sequences of integers in a list:
SeedRandom[1];
list = RandomChoice[Range[10], 10 ^ 7];
SequencePosition[list, Range[6]]Take[list, #]& /@ %Find sequences of words in a list:
words = ExampleData[{"Text", "OriginOfSpecies"}, "Words"];SequencePosition[words, {"groups", "of", "species"}]Find sequences of elements that match a pattern, here giving twin primes:
SequencePosition[Range[1000], {_ ? PrimeQ, _, _ ? PrimeQ}]Find sequences in the first 10 million digits of Pi:
digitsPi = First[RealDigits[N[Pi, 10 ^ 7]]];SequencePosition[digitsPi, {3, 1, 4, 1, 5, 9}]SequencePosition[digitsPi, {1, 2, 3, 4, 5, 6, 7}]SequencePosition[digitsPi, {7, 6, 5, 4, 3, 2, 1}]Find all overlapping sequences in a list:
SequencePosition[Range[10], list_ /; Length[list] == 6, Overlaps -> True]Options (2)
Overlaps (2)
SequencePosition[{a, b, a, b, a, b, a, b}, {a, b, a, b}, Overlaps -> True]SequencePosition[{a, b, a, b, a, b, a, b}, {a, b, a, b}, Overlaps -> False]Allow overlaps starting at different positions:
SequencePosition[{a, b, c, d}, {__}, Overlaps -> True]SequencePosition[{a, b, c, d}, {__}, Overlaps -> False]SequencePosition[{a, b, c, d}, {__}, Overlaps -> All]Properties & Relations (3)
Find the position of a sequence:
SequencePosition[{a, b, 1, 2, c, d, 3, 4}, {__Symbol}, Overlaps -> False]SequenceCases[{a, b, 1, 2, c, d, 3, 4}, {__Symbol}, Overlaps -> False]SequenceCount[{a, b, 1, 2, c, d, 3, 4}, {__Symbol}, Overlaps -> False]Replace the sequence by an expression:
SequenceReplace[{a, b, 1, 2, c, d, 3, 4}, {__Symbol} -> "X"]For lists of characters, SequencePosition is very similar to StringPosition:
text = "For lists of characters SequencePosition is very similar to StringPosition:";SequencePosition[Characters[text], Characters["Position"]]StringPosition[text, "Position"]SubsetPosition matches the elements of the sequence in any order:
SubsetPosition[{1, a, 2, 3, a, b, c}, {a, _Integer}]SequencePosition matches the sequence only in the specified order:
SequencePosition[{1, a, 2, 3, a, b, c}, {a, _Integer}]Related Guides
History
Text
Wolfram Research (2015), SequencePosition, Wolfram Language function, https://reference.wolfram.com/language/ref/SequencePosition.html.
CMS
Wolfram Language. 2015. "SequencePosition." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SequencePosition.html.
APA
Wolfram Language. (2015). SequencePosition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SequencePosition.html
BibTeX
@misc{reference.wolfram_2026_sequenceposition, author="Wolfram Research", title="{SequencePosition}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/SequencePosition.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sequenceposition, organization={Wolfram Research}, title={SequencePosition}, year={2015}, url={https://reference.wolfram.com/language/ref/SequencePosition.html}, note=[Accessed: 13-June-2026]}