Counting occurrences means counting matches of one specified literal string inside source text, with explicit rules for letter case and overlapping matches.

This guide explains how occurrence counting works, how overlapping and non-overlapping searches differ, and how to interpret the reported positions. You can apply the same workflow with the browser-based Count Occurrences tool.

“Occurrence” can describe two different tasks: counting repetitions of one chosen string or building a frequency table for many list values. The workflow here covers the first task because Count Occurrences searches for one literal string. It does not produce separate totals for every unique item in a list.

count occurrences explained
Count Occurrences Explained: Exact Matches and Positions

What an occurrence count measures

A match occurs when the complete search string appears as a consecutive sequence inside the source text. The comparison is literal, so it does not interpret wildcards, regular-expression syntax, or word boundaries. A short search string can therefore match inside a longer sequence unless you choose a source and search text that avoid that situation.

  • The source is the text being inspected.
  • The search text is the one literal sequence being counted.
  • The total is the number of matches produced under the selected case and overlap settings.
  • The position list identifies where matches begin, rather than showing the full matched text again.

Each result is therefore tied to a particular input and set of options. Changing the source, search string, case behavior, or overlap behavior can produce a different count. There is no whole-word mode, so a search for a short token may also find that token inside a longer word or code fragment.

Case and overlap rules change the total

Two settings have the greatest effect on the result. Case sensitivity determines which characters are considered equivalent, while overlap behavior determines whether a match can begin inside the span of an earlier match.

Setting Behavior What it means for the count
Case-sensitive Compares the entered strings exactly. Capitalization must match.
Case-insensitive Lowercases the source and search inputs with English-locale behavior for comparison. Differences in letter case do not prevent a match.
Overlap enabled Advances one JavaScript string unit after each match. A later match may begin inside the previous match.
Overlap disabled Advances by the full length of the matched search string. Matches are handled as separate, non-overlapping occurrences.

The count is produced by repeatedly looking up the literal search string from the current offset, similar to the browser behavior documented for String.indexOf(). Non-overlapping results also reflect how many separate replacements a simple literal replace operation would make. Overlap mode is more appropriate for examining sequences that share characters.

Case-insensitive matching uses a comparison copy of the input rather than rewriting the original. The tool applies English-locale lowercase behavior before searching, but it is not a full linguistic collation engine. The narrower behavior is important when comparing text with locale-specific case rules, accents, or different Unicode representations. MDN’s String.toLocaleLowerCase() reference provides more background on locale-aware lowercasing methods.

Count and inspect exact matches

  1. Paste or type the source text. The source can contain up to 1,000,000 characters. Paste the text as it should be searched because the tool does not trim it, alter line endings, collapse whitespace, or remove duplicate content.
  2. Enter the literal text to find. The search string must be non-empty and can be up to 1,000 characters long. Spaces, tabs, pasted line breaks, emoji, punctuation, and ordinary Unicode text are allowed. Punctuation is treated literally, so characters such as periods, brackets, and asterisks do not need escaping.
  3. Choose the matching behavior. Select case-sensitive or case-insensitive matching, then choose whether overlapping matches are allowed. These are explicit choices, so the tool does not silently change the interpretation based on the input.
  4. Count the matches. The result reports the complete total and displays the first 100 zero-based starting positions. The position list is capped for readability, but the total itself is not truncated, even when hundreds of thousands of matches exist.
  5. Check and interpret the output. A result of zero is valid and displays no positions. Editing either input or changing an option clears the previous output, preventing an old count from being mistaken for the current result. The position preview remains on the page rather than creating a download.

The operation runs locally in the browser. Neither the source text nor the search string is sent to Lizely, and the result does not depend on a remote lookup table or server-side state.

Read zero-based positions correctly

A zero-based offset identifies the string unit where a match starts, with the first position numbered 0. These are JavaScript UTF-16 string offsets, not user-perceived character or grapheme indexes. Most ordinary English characters use one offset, while characters represented by surrogate pairs can use two UTF-16 code units. That distinction can matter when an emoji appears before a later match.

One worked example demonstrates overlapping behavior. Set the source to ababa, set the search text to aba, and enable overlap mode. The first match starts at offset 0. The tool then advances one string unit and finds the next matching sequence at offset 2. The result is a total of 2, with starting positions 0 and 2.

Even in case-insensitive mode, the reported offsets refer to the original source text rather than the lowercased comparison copy. A match can also span a newline when the search string contains that newline, so a position does not always identify a match contained entirely on one visual line.

Supported inputs and matching boundaries

Input and output limits

  • The source accepts up to 1,000,000 characters.
  • The non-empty search string accepts up to 1,000 characters.
  • An empty search string is rejected because it would match at every boundary and produce an ambiguous result.
  • A search string longer than the remaining source naturally produces zero matches.
  • The tool displays at most 100 positions, while retaining the complete match total.

The tool expects pasted or typed content; it does not include a file-upload parser. Its input and output limits protect browser responsiveness and reduce the chance that an extremely large result will make the page difficult to use.

Literal matching only

The search string is not a regular expression. A period matches a period, an asterisk matches an asterisk, and brackets have no special pattern meaning. There is also no fuzzy matching, stemming, wildcard syntax, or whole-word mode. These restrictions make punctuation and code fragments predictable, but they also mean the search text must represent the exact sequence you want to count.

Whitespace and Unicode behavior

The source is not trimmed, normalized, or rewritten. Line endings, whitespace runs, blank lines, and duplicate content remain part of the searchable text. The tool does not perform Unicode normalization, accent folding, or script-specific case inference, so canonically similar but differently encoded strings may not compare as equivalent.

Case folding is used only for the case-insensitive comparison copy. Locale-specific equivalence and full linguistic collation are outside the supported behavior. This makes the tool suitable for repeated words, tokens, separators, log markers, code fragments, IDs, punctuation, and exact phrases when you need deterministic browser-based results.

Choose the method that fits the job

Count Occurrences is the appropriate choice when you have one literal string and need its total or starting positions. Other text tasks require different outputs.

Reader task Recommended tool Reason
Count one literal string and inspect match positions Count Occurrences Supports case and overlap choices, a complete total, and zero-based offsets.
Count words Word Counter Measures document-level text totals rather than repetitions of one specified string.
Change literal matches Find and Replace Produces replacements instead of reporting occurrence counts and positions.
Compare two bodies of text Text Diff Checker Shows differences between versions rather than counting one string within a source.

For a side-by-side comparison of browser and command-line approaches, read Count Occurrences: Command Line vs Online.

Check the result before relying on it

  • Confirm that the search text is the literal sequence you intended to count.
  • Decide whether capitalization should matter, then select the corresponding case option.
  • Select overlap only when matches sharing characters should count separately.
  • Remember that the visible position list contains only the first 100 matches, not every match in the text.
  • Treat zero as a meaningful result rather than an error when the literal sequence is absent.
  • Recheck the count after editing an input or option because the previous result is cleared automatically.

A reliable occurrence count therefore depends on the literal query, the selected comparison rules, and careful interpretation of the offsets—not on a hidden automatic interpretation of the source text.