({{, (RefLink[SequencePosition, paclet:ref/SequencePosition])[list,sublist] 
gives a list of the starting and ending positions at which sublist appears in list.}, {, (RefLink[SequencePosition, paclet:ref/SequencePosition])[list,patt]
gives all positions at which sequences matching patt occur in list.}, {, (RefLink[SequencePosition, paclet:ref/SequencePosition])[list,patt,n]
includes only the first n occurrences of patt.}})

OpenersNotesSection(Spacer1)Details and Options

In (RefLink[SequencePosition, paclet:ref/SequencePosition])[list,patt], patt can be an expression with head (RefLink[List, paclet:ref/List]) that includes pattern constructs such as (RefLink[PatternSequence, paclet:ref/PatternSequence]), (RefLink[Repeated, paclet:ref/Repeated]) (..), (RefLink[Blank, paclet:ref/Blank]) (_), and (RefLink[BlankSequence, paclet:ref/BlankSequence]) (__).

The pattern patt can also be a pattern that matches a list but does not itself have head (RefLink[List, paclet:ref/List]).

With the default option setting (RefLink[Overlaps, paclet:ref/Overlaps])->(RefLink[True, paclet:ref/True]), (RefLink[SequencePosition, paclet:ref/SequencePosition]) includes sublists that overlap. With the setting (RefLink[Overlaps, paclet:ref/Overlaps])->(RefLink[False, paclet:ref/False]), such sublists are excluded.

With (RefLink[Overlaps, paclet:ref/Overlaps])->(RefLink[All, paclet:ref/All]), multiple sublists that match the same pattern are all included. With (RefLink[Overlaps, paclet:ref/Overlaps])->(RefLink[True, paclet:ref/True]), only the first such matching sublist at a given position is included.

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic 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]}]

OpenersExampleSection1(Spacer1)Scope  (5)

Find sequences of integers in a list:

SeedRandom[1];
list=RandomChoice[Range[10],10^7];
SequencePosition[list,Range[6]]

Check the result:

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]

OpenersExampleSection2(Spacer1)Options  (2)

OpenersExampleSubsection0(Spacer1)Overlaps  (2)

Allow overlaps:

SequencePosition[{a,b,a,b,a,b,a,b},{a,b,a,b},Overlaps->True]

Allow no overlaps:

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]

Allow no overlaps:

SequencePosition[{a,b,c,d},{__},Overlaps->False]

Allow all overlaps:

SequencePosition[{a,b,c,d},{__},Overlaps->All]

OpenersExampleSection3(Spacer1)Properties & Relations  (2)

Find the position of a sequence:

SequencePosition[{a,b,1,2,c,d,3,4},{__Symbol},Overlaps->False]

Find the actual sequence:

SequenceCases[{a,b,1,2,c,d,3,4},{__Symbol},Overlaps->False]

Find the number of cases:

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, (RefLink[SequencePosition, paclet:ref/SequencePosition]) is very similar to (RefLink[StringPosition, paclet:ref/StringPosition]):

text="For lists of characters SequencePosition is very similar to StringPosition:";

SequencePosition[Characters[text],Characters["Position"]]

StringPosition[text,"Position"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SequenceCases, paclet:ref/SequenceCases])  ▪  (RefLink[SequenceCount, paclet:ref/SequenceCount])  ▪  (RefLink[SequenceReplace, paclet:ref/SequenceReplace])  ▪  (RefLink[SequenceSplit, paclet:ref/SequenceSplit])  ▪  (RefLink[Position, paclet:ref/Position])  ▪  (RefLink[StringPosition, paclet:ref/StringPosition])  ▪  (RefLink[Take, paclet:ref/Take])  ▪  (RefLink[PatternSequence, paclet:ref/PatternSequence])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Math & Counting Operations on Lists, paclet:guide/MathematicalAndCountingOperationsOnLists])}, {▪(RefLinkPlain[Elements of Lists, paclet:guide/ElementsOfLists])}, {▪(RefLinkPlain[Sequence Alignment & Comparison, paclet:guide/SequenceAlignmentAndComparison])}})}})