({{, (RefLink[LongestCommonSubsequencePositions, paclet:ref/LongestCommonSubsequencePositions])[(Subscript[s, 1]),(Subscript[s, 2])] 
finds the longest contiguous subsequence of elements common to the strings or lists (Subscript[s, 1]) and (Subscript[s, 2]) and returns their positions {(Subscript[pos, 1]),(Subscript[pos, 2])} in (Subscript[s, 1]) and (Subscript[s, 2]).}})

OpenersNotesSection(Spacer1)Details and Options

For lists (Subscript[s, i]), (RefLink[Take, paclet:ref/Take])[(Subscript[s, i]),(Subscript[pos, i])] returns the longest common subsequence. For strings (Subscript[s, i]), (RefLink[StringTake, paclet:ref/StringTake])[(Subscript[s, i]),(Subscript[pos, i])] returns the longest common contiguous substring.

If there are several common subsequences of the same length, (RefLink[LongestCommonSubsequencePositions, paclet:ref/LongestCommonSubsequencePositions]) returns the position of the one that appears earliest in (Subscript[s, 1]).

For strings, setting the option (RefLink[IgnoreCase, paclet:ref/IgnoreCase])->(RefLink[True, paclet:ref/True]) makes (RefLink[LongestCommonSubsequencePositions, paclet:ref/LongestCommonSubsequencePositions]) treat lowercase and uppercase letters as equivalent, and returns the form of common subsequence that occurs in (Subscript[s, 1]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Find the longest contiguous subsequence common to two strings:

LongestCommonSubsequencePositions["AABCC","CBAABA"]

Find the longest contiguous subsequence common to two lists:

LongestCommonSubsequencePositions[{"A","A","B","C","C"},{"C","B","A","A","B","A"}]

OpenersExampleSection1(Spacer1)Scope  (2)

Act on two strings:

LongestCommonSubsequencePositions["This is an example string","And this is another string"]

Act on two lists of expressions:

LongestCommonSubsequencePositions[{5,1,3,0,5,2,3,0,0,5},{1,4,4,1,5,1,3,0,5,3}]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)IgnoreCase  (1)

By default, (RefLink[LongestCommonSubsequencePositions, paclet:ref/LongestCommonSubsequencePositions]) distinguishes lower and upper case:

LongestCommonSubsequencePositions["abcd","ABCD"]

Ignore case:

LongestCommonSubsequencePositions["abcd","ABCD",IgnoreCase->True]

OpenersExampleSection3(Spacer1)Applications  (1)

Longest contiguous DNA subsequence of two genes:

LongestCommonSubsequencePositions[GenomeData["BRCA1"],GenomeData["SCNN1A"]]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Take two strings:

string1="This is an example string";
string2="And this is another string";

Find the positions of the longest common sequence of characters:

{pos1,pos2}=LongestCommonSubsequencePositions[string1,string2]

The corresponding strings coincide:

{StringTake[string1,pos1],StringTake[string2,pos2]}

(RefLink[LongestCommonSubsequence, paclet:ref/LongestCommonSubsequence]) returns those strings joined:

LongestCommonSubsequence[string1,string2]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LongestCommonSubsequence, paclet:ref/LongestCommonSubsequence])  ▪  (RefLink[LongestCommonSequencePositions, paclet:ref/LongestCommonSequencePositions])  ▪  (RefLink[SequencePosition, paclet:ref/SequencePosition])  ▪  (RefLink[LongestCommonSequence, paclet:ref/LongestCommonSequence])  ▪  (RefLink[SequenceAlignment, paclet:ref/SequenceAlignment])  ▪  (RefLink[NeedlemanWunschSimilarity, paclet:ref/NeedlemanWunschSimilarity])  ▪  (RefLink[Longest, paclet:ref/Longest])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Sequence Alignment & Comparison, paclet:guide/SequenceAlignmentAndComparison])}})}})