Counting occurrences means finding how many times a specific literal string appears inside a larger body of text and reporting both the total count and the exact starting positions of each match. The Count Occurrences tool runs that search entirely inside the browser, accepts up to 1,000,000 characters of source text, and treats the search string literally — a period matches a period and an asterisk matches an asterisk, with no regular-expression syntax to escape and nothing to learn. You can switch between case-sensitive and case-insensitive matching and decide separately whether matches are allowed to overlap, so the same input can produce different counts depending on how you intend to use the result. The tool reports the total without truncation and lists the first 100 zero-based starting positions so even a result with hundreds of thousands of matches stays readable. Because the matching, counting, and position collection all happen locally, the pasted text and the search string never leave your tab, which makes the tool suitable for log files, draft manuscripts, source code, and any other text you would rather not upload.

count occurrences
Count Occurrences of a String in Text and See Positions

An occurrence counter answers a single question: how many times does this exact substring appear inside that body of text? When the comparison is literal, the answer depends only on the characters themselves, not on any pattern language. Searching for the literal string file.txt will find every appearance of those nine characters in that order and will not treat the period as a wildcard or as a token that means "any character". This is what makes a literal counter predictable for everyday work such as checking repeated words, separators, log markers, IDs, punctuation, and short code fragments.

Because the tool does not compile a regular expression, an invalid pattern can never break the search and users never have to escape punctuation. A bracket in the search string matches a bracket in the source, an opening parenthesis matches an opening parenthesis, and a backslash matches a backslash. The case-insensitive option applies an English-locale lowercase transformation to both sides through the standard String toLocaleLowerCase behaviour before comparing, which is a practical shortcut rather than a full linguistic collation engine. Locale-specific equivalence, normalization between composed and decomposed Unicode forms, accent folding, and script-specific case rules are not inferred, so if your text depends on those features a literal counter is the wrong tool.

How to Count Occurrences in Text

  1. Paste or type the source text you want to search into the main input field. You can enter up to one million characters; the tool does not trim, reflow, or otherwise rewrite what you provide.
  2. Enter the literal text to find in the search field. The search string can contain spaces, tabs, line breaks pasted into the field, emoji, or ordinary Unicode text up to 1,000 characters, and an empty search string is rejected because it would match at every boundary and produce an ambiguous result.
  3. Choose whether matching should be case-sensitive or case-insensitive, then choose whether matches may overlap. Editing any input or option clears the old output so stale counts cannot be mistaken for current settings.
  4. Count matches and review the result. The output shows the total count — which is not truncated even when it runs into the hundreds of thousands — together with the first 100 zero-based starting positions of every match in the original source text.

Overlapping vs Non-Overlapping Matches

The overlap setting changes how the search advances after a match and therefore changes the count for any search string that can sit inside itself. Non-overlapping mode advances past the entire matched search string, so it reflects how many separate replacements a simple literal replace operation would make. Overlapping mode advances by one JavaScript string unit after a match, which is useful for sequence analysis where you want every possible placement of the search string counted.

ModeHow it advancesTypical useSource: aaaa, search: aa
Non-overlappingFull search-string lengthReplace planning, repeated-word auditsTotal 2, positions 0 and 2
OverlappingOne string unitSequence analysis, substring detectionTotal 3, positions 0, 1, and 2

The example above deliberately uses a tiny string so the result can be verified by hand. Non-overlapping mode looks at the source aaaa and finds aa at position 0, then advances past both matched characters and finds the next aa at position 2, for a total of two matches. Overlapping mode finds aa at position 0, advances by one character, finds another aa at position 1, advances by one character, and finds a third aa at position 2, for a total of three matches. Both interpretations are common in everyday counting tasks, and the tool offers both as an explicit option rather than switching silently based on the input.

Reading the Position Numbers Correctly

The starting positions that Count Occurrences reports are zero-based JavaScript string offsets, meaning the first character of the source is at position 0, the second is at position 1, and so on. For most ordinary English text each visible character consumes one offset, so position numbers match what you would count on your fingers. Internally the search repeats the standard String indexOf lookup starting from the current offset until no further match can be found, retaining every count while displaying only the first 100 original-string offsets.

Some characters consume two offsets instead of one. Characters outside the Unicode Basic Multilingual Plane — most emoji, many historical scripts, and certain mathematical symbols — are encoded in JavaScript as surrogate pairs, so each such character occupies two UTF-16 code units. The position numbers you see therefore describe code-unit offsets rather than user-perceived grapheme indexes. If you copy a position back into your own JavaScript code it will land on the same character; if you copy it back into a grapheme-aware application you may need to adjust by one for every emoji that appears earlier in the text.

When Zero Is the Right Answer

A zero result is a valid answer and the tool simply displays no positions alongside it. There are several ordinary reasons a count can come back as zero. The simplest is that the search string does not appear in the source at all, which is exactly what should happen when an identifier, marker, or phrase is genuinely absent. Case sensitivity can hide matches even when the letters look identical, especially when the source uses mixed casing such as ERROR on one line and Error on the next while the matching mode is set to case-sensitive. A search string longer than the remaining source naturally returns zero, because there is no room for the pattern to fit.

Whitespace inside the search field can also produce silent zero results, because a space at the end of error is part of the literal pattern rather than decoration. Because the tool never uploads your text, leaves no account state behind, and clears its output as soon as you edit either input, a zero result carries the same weight as any other count. Treat it as evidence rather than as an error, and re-check the case sensitivity setting, the overlap setting, and the exact contents of the search field before assuming the source is wrong.

Picking the Right Counter for the Job

Count Occurrences answers one specific question and stays close to its source so the answer is auditable. Other text counters on this site answer related questions, and the table below shows when to switch tools.

ToolQuestion it answersWhat it returns
Count OccurrencesHow many times does this literal string appear?Total plus the first 100 zero-based starting positions
Word CounterHow many words, characters, sentences, and minutes of reading does this passage contain?Bulk counts for an entire passage as you type
Find and ReplaceHow do I change every literal match into something else?Edited text using the same literal, no-escape matching rules
Text Diff CheckerWhich lines differ between two versions of a text?Added, removed, and unchanged line sets, not a frequency count

Reach for Count Occurrences when you already know the substring you want to tally and want both the total and a reproducible starting offset. Reach for Word Counter when the question is how big a passage is and you do not have a specific pattern in mind. Reach for Find and Replace when you actually want to edit the matches rather than count them, since it uses the same literal, no-escape matching rules and will not surprise you with regex syntax. Reach for the Text Diff Checker when the question is whether two files are the same rather than how often a string appears.