All Articles
Text

Remove Extra Spaces Without Flattening Paragraphs

November 6, 20263 min read

To collapse repeated spaces but keep your paragraphs, turn on Regular Expression, search for [ \t]{2,} and replace with a single space. That pattern only matches runs of two or more spaces or tabs, so line breaks are left alone. The popular \s+ pattern also matches line breaks, which is why it flattens a document into one line.

Find and Replace with Regular Expression on, pattern [ \t]{2,}: 3 matches replaced, the blank line between the two paragraphs is kept
Pattern [ \t]{2,}, 3 replaced. The blank line between paragraphs survives. Open Find & Replace.

Try it with this sample

Copy this into Input Text. The first line has double and triple spaces; there is a blank line, then a line with a single tab after “Second” and two spaces before “here”.

red  blue   green

Second	paragraph  here.
  1. In Find, type [ \t]{2,}. In Replace with, type one space.
  2. Click Regular Expression so it turns blue. The badge next to Find shows 3 matches.
  3. Click Replace All. The Result panel shows 3 replaced and this text:
red blue green

Second	paragraph here.

The single tab after “Second” is still there, because the pattern needs at least two characters in a row. If you also want lone tabs turned into spaces, run a second pass with \t and a space.

What \s+ does to the same text

\s means any whitespace character: spaces, tabs and line breaks. Replacing \s+ with one space therefore also replaces the blank line.

Same sample with pattern \s+: 6 replaced and the result is one line, red blue green Second paragraph here.
\s+ replaced 6 runs, including the line breaks. Both paragraphs are now one line.
red blue green Second paragraph here.

That is useful when you really want a single line (for example, a value for a one-line form field), but not for cleaning a document.

Be careful with indented text

Code, poetry and plain-text tables often use runs of spaces on purpose. A global cleanup removes that alignment too. Paste only the prose you want to clean, or clean it in sections.

If it doesn't work

  • Nothing matches: check that Regular Expression is on. With it off, the tool searches for the literal characters [ \t]{2,}.
  • Words got glued together: the Replace with box was empty. It needs one space.
  • Still double-spaced after a period: some text uses a non-breaking space, which [ \t] does not include. Try [ \t\u00A0]{2,}.
  • Looks different after pasting elsewhere: rich-text editors and web pages can render spacing differently. Check the final destination and keep your original until it looks right.

Everything runs in your browser; the text is not uploaded. Open the free Find & Replace tool.

find and replacetext cleanupregex