Find repeated spaces
Catch double and triple spaces left behind by copy-paste or old typewriter habits, so prose reads clean instead of gappy.
Last updated
Matches
- Hello world
- Too many spaces
Doesn’t match
- Single spaced text here
- Tabs are not spaces
Why it’s written this way
The pattern is a literal space with the {2,} quantifier, so it matches any run of two or more consecutive spaces without caring what surrounds them.
It carries no anchors, so it fires anywhere in the text — mid-sentence, at the start of a line, or between words — which is exactly what you want when hunting formatting noise across a whole document.
Edge cases to know
- →It ignores tabs entirely — a tab used for alignment won't trip this pattern the way a stray double space will.
- →Two spaces inside a code block or a Markdown table, where they can be meaningful, get flagged the same as an accidental double space in prose.
Part by part
- {2,}
- A literal space with a quantifier of two or more. The space is significant and easy to lose when the pattern is copied through an editor that trims.
Common mistakes
\s{2,}The whitespace class includes newlines, so two consecutive line breaks match and a replace collapses paragraph separation into a single space. It destroys document structure while appearing to tidy it.
{2,}+One or more matches every single space in the document, so a replace rewrites the entire text and reports a match on every word gap. The minimum of two is the whole point.
{2}Exactly two leaves longer runs partly intact: four spaces become two matches, and with a replace to one space you are left with two spaces rather than one. The open-ended quantifier collapses any run in a single pass.
Questions
Will it break code indentation?
Yes, badly. Indentation is runs of spaces at the start of a line, and this pattern cannot tell them from accidental doubles mid-sentence. Never run it across source files without anchoring it away from line starts.
What about the two spaces after a full stop?
That convention comes from monospaced typewriters and is no longer standard in proportional type, but it is a deliberate choice in some house styles. This pattern will collapse them, so check before running it on prose you did not write.
Does it catch tabs used as spacing?
No, only literal spaces. A mixed run of a space and a tab is left alone, which is often the more interesting problem — use the character-inspector tool when you suspect mixed whitespace rather than doubled spaces.
Why not just use trim?
Trim only removes whitespace at the two ends of a string. This finds runs anywhere inside it, which is where doubled spaces actually accumulate — after an edit that deleted a word and left both its spaces behind.
How do I collapse doubles without touching indentation?
Anchor the match away from the start of the line by requiring a non-space before the run: something like (?<=\S) {2,} with the m flag leaves leading indentation alone while still collapsing runs inside a sentence. Lookbehind is well supported in modern JavaScript, Python and .NET, though not universally, so test it in the engine you are using.