finds the longest sequence of contiguous or disjoint elements common to the strings or lists s1 and s2 and returns their positions.

Details and Options

  • LongestCommonSequencePositions[s1,s2] returns an expression of the form {pos1,pos2} where the posi specify the positions of the longest common sequence in the strings or lists si.
  • For lists si, Take[si,posi] returns the longest common sequence. For strings si, StringTake[si,posi] returns the longest common contiguous or disjoint substring.
  • If there are several common sequences of the same length, LongestCommonSequencePositions returns the one that begins earliest in s1.
  • For strings, setting the option IgnoreCase->True makes LongestCommonSequencePositions treat lowercase and uppercase letters as equivalent, and returns the form of common sequence that occurs in s1.


open allclose all

Basic Examples  (2)

Find the longest noncontiguous sequence common to two strings:

Click for copyable input

Find the longest noncontiguous sequence common to two lists:

Click for copyable input

Scope  (2)

Options  (1)

Properties & Relations  (1)

See Also

LongestCommonSequence  LongestCommonSubsequencePositions  SequencePosition  LongestCommonSubsequence  SequenceAlignment

Introduced in 2015