Skip to content
ZeroServer.tools

Remove Extra Spaces

Collapse repeated spaces and trim each line.

Characters: 0Words: 0Lines: 0

Tidying Messy Whitespace

Text copied from PDFs, spreadsheets, or chat logs often carries irregular spacing — double spaces, stray tabs, and trailing whitespace. This tool collapses every run of spaces and tabs into a single space, trims the start and end of each line, and can optionally merge repeated blank lines into one. It never touches the words themselves, and all processing happens locally in your browser.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Collapsing double spaces after sentence-joining in an edited draft.
  • Tidying text pasted from a PDF with irregular spacing.
  • Trimming each line before an exact-match comparison.
  • Normalising a list where entries were manually aligned.
  • Cleaning input before using it as a key.

Frequently Asked Questions

What exactly is removed?
Runs of consecutive spaces collapse to one, and leading and trailing whitespace goes. Line structure is preserved unless you ask otherwise — collapsing newlines as well is a different, more destructive operation.
Are non-breaking spaces handled?
They must be handled explicitly, and this is the usual reason 'extra spaces' survive removal. U+00A0 is not matched by a plain space pattern, and text pasted from Word or a web page is full of them.
Which other invisible characters cause this?
Several: zero-width space (U+200B), thin and hair spaces (U+2009, U+200A), ideographic space (U+3000) and the zero-width no-break space. A \s regex in JavaScript catches some but not the zero-width ones.
Why do two spaces after a full stop persist?
It is a typewriter-era convention, kept alive by muscle memory and some style guides. HTML collapses them automatically on render, so they are invisible on the web but present in the source and in plain-text output.
Does this affect code?
Yes, and destructively for indentation-sensitive languages. Collapsing runs of spaces breaks Python and YAML outright. Use a code formatter for source files rather than a whitespace collapser.
Does it touch line breaks?
Collapsing runs of spaces and tabs is separate from collapsing blank lines, and conflating them destroys paragraph structure. Horizontal whitespace within a line is the safe thing to normalise by default.
Why does text pasted from a PDF have odd spacing?
Because PDFs position glyphs rather than storing words, so the extractor infers spaces from gaps — producing runs of spaces, missing spaces inside words, and occasionally a space between every letter.
Is leading indentation preserved?
It has to be for code and for Markdown, where indentation is syntax. Collapsing it silently turns a nested list flat and a code block into a paragraph, which is why indentation is treated separately from interior runs.

Common errors and gotchas

  • Collapsing spaces inside code or a preformatted block, where alignment matters.
  • Removing a deliberate double space in a house style that uses it after sentences.
  • Collapsing a non-breaking space that was there for a reason.
  • Trimming a value that a downstream system pads to a fixed width.
  • Overlooking tabs, which are whitespace but not spaces.

Related Text Tools tools

Private & free — this tool runs entirely in your browser.