Function Repository Resource:

StringOverlaps

Source Notebook

Find substrings that overlap between strings

Contributed by: Stephen Wolfram

ResourceFunction["StringOverlaps"][{string1,string2,}]

gives a list of overlaps that exist between any of the stringi.

ResourceFunction["StringOverlaps"][string]

gives overlaps of string with itself.

Details

ResourceFunction["StringOverlaps"] returns a sorted list of unique overlaps.
An overlap between two strings occurs when the suffix of one matches the prefix of the other.
A self-overlapping string represents the case in which its suffix matches its prefix.

Examples

Basic Examples (3) 

Find the overlap between two strings:

In[1]:=
ResourceFunction["StringOverlaps"][{"AAB", "BCC"}]
Out[1]=

Find the overlaps between two strings in either order:

In[2]:=
ResourceFunction["StringOverlaps"][{"BAC", "CAB"}]
Out[2]=

Find the overlaps of a string with itself:

In[3]:=
ResourceFunction["StringOverlaps"]["AABAA"]
Out[3]=

Scope (3) 

Find all pairwise overlaps between a list of multiple strings:

In[4]:=
ResourceFunction["StringOverlaps"][{"AB", "BC", "CD"}]
Out[4]=

A string with distinct prefix and suffix does not have overlaps:

In[5]:=
ResourceFunction["StringOverlaps"]["AABB"]
Out[5]=

Constant strings have overlaps that vary in length:

In[6]:=
ResourceFunction["StringOverlaps"]["AAAA"]
Out[6]=

Properties and Relations (2) 

Use LongestCommonSequence to find the common sequence between two strings:

In[7]:=
LongestCommonSequence["ApplePie", "PieChart"]
Out[7]=

StringOverlaps returns the combination of the strings:

In[8]:=
ResourceFunction["StringOverlaps"][{"ApplePie", "PieChart"}]
Out[8]=

Version History

  • 1.1.0 – 19 November 2025
  • 1.0.0 – 04 December 2019

Related Resources

Author Notes

Version 1.1 adds support for more than two strings as the input.

License Information