Extra spaces are the most common kind of messy text. They come from justified PDFs, old typing habits (two spaces after a full stop), tab-aligned documents and web pages that use non-breaking spaces for layout.

The quick way

Paste your text into Remove Extra Spaces. By default it:

  • replaces every run of spaces, and every tab, with a single space;
  • converts non-breaking and other special spaces to ordinary spaces;
  • trims spaces from the start and end of each line;
  • reduces several blank lines to one.

Your line breaks and paragraphs are kept.

The kinds of spaces you can’t see

Not every space is the same character. Common invisible troublemakers:

CharacterWhere it comes from
TabDocuments and spreadsheets with aligned columns
Non-breaking space (U+00A0)Web pages, word processors, French typography
Thin and narrow spaces (U+2009, U+202F)Typeset documents and number formatting
Trailing spacesAlmost everything; invisible at the end of lines

These make searches fail and “identical” values not match. The Character Counter can help you spot them: if the character count is higher than you expect, hidden spaces are a likely cause.

Only the edges of lines

If spaces inside lines matter, for example in tab-separated data or code, but leading and trailing spaces don’t, use Trim Lines instead. It leaves everything between the first and last visible character alone.

Using find and replace

In Word, Google Docs and most editors you can replace two spaces with one. Repeat until nothing is found, because three spaces become two on the first pass.

Code editors that support regular expressions, such as VS Code, Notepad++ and Sublime Text, can do it in one step:

  • Collapse runs of spaces and tabs: find [ \t]{2,} and replace with a single space.
  • Remove trailing whitespace: find [ \t]+$ and replace with nothing.
  • Reduce blank lines: find \n{3,} and replace with \n\n.

Google Docs also offers “Match using regular expressions” in Find and replace, which handles the first pattern, but it cannot match line breaks.

Spaces before punctuation

“Hello , world !” needs a different fix: removing the space before the punctuation mark. Turn on Remove spaces before punctuation in the tool. Leave it off for French text, where a space before ; : ! and ? is correct.