ForHosting KIT · Text & AI

Repeated substring pattern detector

Find out whether a string is just one fragment written over and over: ababab is ab three times and aaaa is a four times, while aba does not repeat. You get the smallest unit and the exact count. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
ababab
You get
Unit length
2
Quantity
3
Length
6

Many interview problems and data-cleaning checks ask a simple question: is this string just one shorter fragment written over and over? Strings such as ababab, aaaa, and xyzxyzxyz are built that way; abc and aba are not. This repeated substring pattern detector accepts a single non-empty text field, runs a deterministic KMP border (longest proper prefix-suffix) analysis, and returns the smallest repeating unit together with the exact repeat count. There is no network call, no randomness, and no clock dependency—only string arithmetic you can re-run byte for byte.

What a repeated substring pattern is and how the unit is chosen

A string has a repeated substring pattern when it equals some non-empty unit written end to end at least twice with no leftover characters. For example ababab is the unit ab written three times, aaaa is the unit a written four times, and xyzxyz is the unit xyz written twice. The detector always returns the smallest such unit: if a string can be tiled by both ab and abab, the answer is ab with a larger count, not the longer candidate.

When no shorter unit tiles the full length, the string is reported as not repeated: unit equals the original text and count equals one. The classical linear-time test builds the KMP longest proper prefix-suffix table for the string of length n, sets period to n minus the final border length, and checks whether period divides n and is strictly smaller than n. If both hold, the unit is the prefix of length period and the count is n divided by period.

This matches the brute-force divisor scan that tries every length from one through floor of n over two, but stays O(n) and never depends on floating clocks or random seeds. Single-character strings and empty results of validation are handled explicitly: length one cannot be a non-trivial repeat, and empty or missing text is rejected before any LPS work runs.

Where a repeated-pattern detector earns its keep

Interview prep and algorithm courses use this problem to teach borders, periods, and divisor arguments; a live detector lets students check ababab versus aba without hand-rolling LPS tables under time pressure. Data-quality pipelines flag columns that look like accidental copy-paste repeats (SKU SKU SKU, yesyesyes) before they pollute search indexes or analytics. Compression and encoding demos illustrate run-length style structure without claiming to be a full compressor: showing that xyzxyzxyz is three copies of xyz is often enough for a lecture slide.

Failed validation does not consume balance.

Interview and algorithm practice

Check whether a string is a non-trivial repeated pattern and name the smallest unit and count against textbook KMP and divisor solutions.

Data quality and duplicate paste checks

Flag cells or tokens that are pure repeats of a shorter fragment before they enter indexes, catalogs, or analytics.

How do I detect a repeated substring pattern?

Send a non-empty string in the text field. When the string is not a non-trivial repeat, unit is the full string and count is 1.

What is the smallest repeating unit?

It is the shortest non-empty prefix that tiles the whole string with no remainder. For ababab the unit is ab (not abab). For aaaa the unit is a.

Which algorithm does the detector use?

A KMP longest proper prefix-suffix (LPS) period test: if period = n - lps[n-1] divides n and is shorter than n, the unit is the prefix of that length. Equivalent to trying every divisor length, but linear time.

What do I get when the string does not repeat?

A normal answer, not an error: the result says it is not repeated, the unit is the whole string and the count is one. Ordinary unique strings such as abc are handled the same way.

Does the unit have to fill the whole string?

Yes. A string counts as repeated only when the unit, written end to end at least twice, covers it with no characters left over. That is why aba is not a repeat, even though it starts and ends with a.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev/repeated-substring

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev/repeated-substring \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"ababab"}'
{
  "text": "ababab"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.repeated_substring",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

When no shorter unit tiles the whole string, the response marks is_repeated false, sets unit to the full string, and sets count to one so callers always get a stable contract.

What a repeated substring pattern is and how the unit is chosen

That contract is friendlier for pipelines than a hard error on non-patterns, because callers can branch on is_repeated without treating ordinary unique strings as invalid input.

Input contract, response fields, and error behaviour

Example: aaaa yields unit a and count four. Keep inputs under the documented character ceiling; oversized pastes fail with an explicit limit message rather than a truncated silent cut. POST a JSON body with a required text field holding a non-empty string. Aliases input, string, value, s, and source are accepted so query forms, spreadsheets, and typed SDK wrappers can reuse the same contract without renaming columns. Finite numbers and bigints are stringified first so a product code typed as a bare number still analyses cleanly; booleans, plain objects, and arrays are rejected so a mistaken JSON body does not become the word true or an unhelpful object dump. Empty strings and missing text fail with invalid_input and are not billed. On success the body includes text (echo of the analysed string), is_repeated (true when count is at least two), unit (smallest repeating fragment, or the full string when not repeated), unit_length, count, length of the original text, and method fixed to kmp_period for logs and multi-tool pipelines. Example: ababab yields unit ab, unit_length two, count three, is_repeated true. Example: abc yields unit abc, count one, is_repeated false. Pair the free browser run on this page with the priced API when you need the identical unit and count inside CI, grading scripts, or edge workers without re-implementing KMP yourself.

Where a repeated-pattern detector earns its keep

Teachers and LMS authors need a deterministic oracle that returns both the boolean pattern flag and the concrete unit so auto-graders can accept any correct explanation that names the same smallest fragment.

LMS and homework auto-grading

Mark repeated-substring items with a deterministic oracle that returns unit, count, and is_repeated for stable comparison.

What if the string is not repeated?

The call still succeeds: is_repeated is false, unit equals the original text, and count is 1. Only missing or empty text is invalid_input.

What does the repeated substring pattern detector cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →