How to recognize recurring patterns in string ? For music chords chorus/verse automatic recognition

I work in JS and am seeking for a way of recognizing repeating patterns in chords from songs.

Here is the input (hotel california chords):

Am E7 G D F C Dm E7 F C E7 Am F C Dm E7 Am E7 G D F C Dm E7 Am E7 G D F C Dm E7 F C E7 Am F C Dm E7 Am E7 G D F C Dm E7 Am E7 G D F C Dm E7 F C Dm E7 Am E7 G D F C Dm E7 Am E7 G D F C Dm E7 Am E7 G D F C Dm E7 Am E7 

And here is the results I’m looking for:

Am E7 G D F C Dm E7
F C E7 Am F C Dm E7
Am E7 G D F C Dm E7
Am E7 G D F C Dm E7
F C E7 Am F C Dm E7
Am E7 G D F C Dm E7
Am E7 G D F C Dm E7
F C Dm E7
Am E7 G D F C Dm E7
Am E7 G D F C Dm E7
Am E7 G D F C Dm E7
Am E7 G D F C Dm E7

As you can see, 2 long patterns have been found: Am E7 G D F C Dm E7 and F C E7 Am F C Dm E7 so the string was split accordingly. The rest of the non-patterns remains as it is and the minimum pattern length should be 3 to avoid too short patterns.

Of course, patterns are not given but should be idendtified on their own by the algorithm.
Any simple (or less simple) ways to do that?