Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Find all repeating substrings of length >= n in js

I want to find patterns in a string for compression.

Lets say I have a string, "abcdabcr".

I want to find repeating patterns of length 2 or more, eg abc, not overlapping.

How can I do this?

I have tried searching this, but it is hard to find answers.

I have this code:

function findPatterns(str) {
    let sbf=[]
    let patterns=[]
    let chunks = str.match(/.{1,2}/gm)
    chunks.forEach((c)=>{
        if (sbf.includes(c)) {
            patterns.push(c)
        }
        sbf.push(c)
    })
    return [...new Set(patterns)]
}

It works for finding patterns of length = 2, but not length >= 2.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!