Remove Extra Spaces

Tidy up messy text from PDFs, emails and spreadsheets: collapse double spaces, trim lines and drop blank lines.

1 characters removed

Last reviewed:

Where extra spaces come from

Extra spaces sneak in from almost every copy and paste. PDFs pad justified lines and columns with spaces. Web pages use non-breaking spaces that look normal but behave differently. Spreadsheets pad cells, old documents use two spaces after every period, and text lined up by hand with the space bar turns into a mess as soon as the font changes.

Cleaning does three things: runs of spaces become one space, tabs become spaces, and (if you choose) each line is trimmed at both ends and empty lines are dropped. Single spaces between words are left alone.

The whitespace characters you can't see

CharacterLooks likeUsually comes fromWhat cleaning does
Space (U+0020)A normal gapTypingRuns of two or more become one
Non-breaking space (U+00A0)Exactly the same gapWeb pages, word processorsRuns become one normal space
Tab (U+0009)A wide gapSpreadsheets, codeBecomes a space
Line breakA new lineThe Enter key, PDFsKept; empty lines can be removed
Zero-width space (U+200B)Nothing at allSome web pages and appsNot touched; see the tip below

If two words still refuse to match after cleaning, a zero-width space may be hiding between letters. In Find and Replace, turn on Regular expression, search for \u200B and replace it with nothing.

Why stray spaces break spreadsheets and searches

To a computer, “Smith” and “Smith ” with a trailing space are different values. That one invisible character makes spreadsheet lookups return errors, stops duplicate checks from matching, and makes a pasted discount code or tracking number fail. Trimming each line fixes all of these at once.

Example: A line copied from an invoice PDF

  1. Original: two leading spaces, “Total:”, three spaces, “42 items”, two trailing spaces (21 characters)
  2. Cleaned: “Total: 42 items” (15 characters)

6 invisible characters removed, and the line now matches “Total: 42 items” anywhere else.

Codes are the worst case. A gift card number, booking reference or tracking number copied from an email often brings a trailing space along. Plenty of forms reject it with a vague “invalid code” message, and you can stare at it for minutes without seeing anything wrong. Paste it here, trim, and copy it back.

Cleaning text from PDFs, emails and spreadsheets

Each source leaves its own kind of mess, so it helps to know what you're dealing with before you paste.

SourceTypical problemWhat fixes it
PDFRuns of spaces from justified text, plus a line break at the end of every lineClean spaces here, then join lines
Web pageNon-breaking spaces and blank lines between every paragraphClean spaces with empty lines removed
Reply-quoted emailIndented lines and double spaces after periodsTrim each line and collapse spaces
Spreadsheet columnTrailing spaces in cells, tabs between columnsTrim each line; keep a copy if you need the tabs

Spaces before punctuation are a different problem: “Hello , world !” has single spaces, so collapsing runs won't touch them. In Find and Replace, turn on Regular expression, find \s+([,.;:!?]) and replace it with $1. The result is “Hello, world!”.

One space or two after a period

The two-space habit dates from typewriters, where every letter took the same width and an extra space made sentence breaks easier to see. Proportional fonts already space punctuation well, and most current style guides, including Chicago and APA (since its 7th edition), call for one space.

Because cleaning collapses every run of spaces, it converts a whole document from two spaces to one in a single pass. If a teacher or publisher really does want two, keep your original and don't clean it.

Double spacing also inflates character counts by one per sentence. A 300-sentence report typed that way carries about 300 extra characters, which matters when an abstract or application form has a character limit.

When not to remove spaces

Some text depends on its spacing. Cleaning it would quietly break the very thing you need, so keep an untouched copy of anything on this list.

  • Python and YAML files, where indentation is part of the meaning. Trimming lines removes it.
  • Tab-separated data copied from a spreadsheet. Tabs become spaces, so columns merge when you paste back.
  • Fixed-width tables or text art lined up with spaces.
  • Poetry or song sheets with deliberate indents.

For text from PDFs, cleaning spaces is usually half the job. Follow it with Remove Line Breaks to rejoin sentences split across lines, and Remove Duplicate Lines if you're cleaning a list.

Sources and further reading

How to use it

  1. 1Paste the messy text.
  2. 2Choose what to clean.
  3. 3Copy the tidy result.

Questions

Will it remove single spaces between words?

No. Only repeated spaces are collapsed to one.

Is my text uploaded anywhere?

No. Everything happens in your browser; your text never leaves your device.

Also handy: Text to QR Code, Shuffle a List