Skip to content

Remove Extra Spaces

Clean up messy text by collapsing double spaces, trimming lines and removing blank lines or tabs.

Runs in your browserFree, no sign-up

Settings

Results update automatically as you type.

Cleanup

Before
84 chars
After
71 chars
Removed
13 chars

Cleaned text

This sentence has too many spaces.\n\n And this line is indented oddly.

About the Remove Extra Spaces

This tool removes extra spaces and other whitespace debris from text that has been copied out of a PDF, an email chain or a badly formatted document. Five independent options let you collapse runs of repeated spaces down to one, trim each line, delete blank lines, turn tabs into spaces and pull punctuation back against the word it belongs to. Line breaks are preserved by default so your paragraph structure survives. A before-and-after character count shows exactly how much was stripped, and the whole clean-up runs in your browser with nothing uploaded.

How to use the Remove Extra Spaces

  1. 1

    Paste the messy text into the 'Your text' box.

  2. 2

    Choose which clean-ups to apply: 'Collapse repeated spaces', 'Trim each line', 'Remove blank lines', 'Convert tabs to spaces' and 'Fix spaces before punctuation'.

  3. 3

    Compare the Before, After and Removed character counts in the Cleanup panel.

  4. 4

    Copy the cleaned text, or download it as cleaned.txt.

What people use it for

Text copied out of a PDF

PDFs place glyphs at coordinates rather than storing flowing text, so copying produces double spaces where the renderer justified a line and stray indentation at the start of each row. Collapsing spaces and trimming lines fixes most of it in one pass.

Cleaning up pasted email threads

Forwarded messages arrive with quoted indentation, tab characters and blank lines between every paragraph. Removing blank lines and converting tabs turns the thread back into readable prose.

Tidying copy for a CMS

Spaces before commas and full stops are the classic sign of text written in French conventions or typed hastily. The punctuation option removes them so the copy matches English typographic norms.

The order the clean-ups run in

The options are applied in a fixed sequence, and knowing it explains results that otherwise look surprising. Tabs are converted to single spaces first, so that a tab sitting next to a space becomes two spaces which the next step can then collapse. Repeated spaces are collapsed second, using a pattern that matches any whitespace except a newline, meaning indentation and mid-sentence gaps shrink to one space while your line structure is untouched. Punctuation spacing is fixed third, removing whitespace that appears immediately before a comma, full stop, semicolon, colon, question mark or exclamation mark. Line trimming runs fourth, stripping leading and trailing whitespace from every individual line. Blank line removal runs last, so lines that only became blank because they contained nothing but spaces are also caught. Finally the whole block is trimmed at both ends. The practical consequence is that turning off 'Trim each line' while leaving 'Collapse repeated spaces' on will reduce a deep indent to a single space rather than removing it, which is often exactly what you want when indentation carries no meaning but a word boundary does.

The whitespace you cannot see

Not every space is the ordinary space at code point 32. Text pasted from web pages and word processors regularly contains a non-breaking space (U+00A0), inserted by HTML entities and by Word's automatic spacing after certain abbreviations. It looks identical, but many programs will not break a line at it and simple search-and-replace routines miss it. The collapse and trim steps here operate on the full Unicode whitespace class, so non-breaking spaces, en spaces, em spaces, thin spaces and the ideographic space used in Japanese and Chinese text are all recognised and handled. Zero-width characters are a different problem: the zero-width space, zero-width joiner and the byte order mark that sometimes leads a file are not whitespace at all in Unicode terms, so they survive the clean-up while remaining invisible. If a line still refuses to match another after cleaning, an invisible zero-width character is the usual culprit, and the character counter will reveal it as an unexpected extra character.

Tips

  • Keep 'Remove blank lines' off when cleaning prose — those blank lines are what separate your paragraphs.
  • Run this before a word count or a deduplication; both give wrong answers on text with hidden trailing spaces.
  • The Removed figure is a good sanity check: a huge number usually means the source was padded with indentation rather than real content.

Frequently asked questions

Does it remove line breaks?
No. Line breaks are preserved so your paragraph structure stays intact. You can optionally remove blank lines between paragraphs.
Why does text copied from a PDF have odd spacing?
PDFs position text visually rather than as flowing words, so copying often produces double spaces, stray tabs and line breaks mid-sentence. This tool cleans most of that up.
What does 'fix spaces before punctuation' do?
It removes spaces that appear before a comma, full stop, colon, semicolon, question mark or exclamation mark.

Looking for something else? Browse all text tools or see every tool.