Remove Extra Spaces
Collapse double spaces, trim the ends of every line, and clear out the invisible spaces that came along with a copy from a web page.
Runs 100% in your browser•Nothing is uploaded to a server•Instant results
Options
Also clean up
Each of these runs the same code as its own page. The full set, all switched on at once, is the text cleaner.
Input
Before and after
Why pasted text ends up full of spaces you did not type
Most double spaces are not typed on purpose. They arrive: a sentence written on a typewriter-era keyboard keeps the two spaces after the full stop, a table copied out of a PDF lands as columns padded out with runs of spaces, and a paragraph pulled off a web page brings the indentation of the HTML source with it. This tool collapses each run down to a single space and trims the leading and trailing whitespace off every line, which is the shape almost every destination actually wants.
The mode select is the whole decision. Collapse and trim is the default and the right answer for prose. Keep the leading indentation matters when you are cleaning code or a YAML block, where the indentation is meaning rather than noise and only the runs inside a line are the problem. Trim only leaves interior spacing intact and just deals with the invisible whitespace hanging off the ends of lines — the kind that shows up as a red block in a diff and adds a stray line break to Markdown. Delete every space is for the case where the spacing itself is the corruption, such as a card number or a hash that got wrapped and padded in transit.
The two checkboxes deal with the whitespace you cannot see. Tabs to spaces converts tab characters that would otherwise survive a collapse pass untouched, because a tab is not a space and a naive space-squeezing regex walks straight past it. Non-breaking and zero-width spaces is the one that solves the mystery case: text copied out of a web page routinely carries U+00A0 (a non-breaking space), U+2009 (a thin space) or U+200B (a zero-width space). They look exactly like ordinary spaces on screen, so a find-and-replace of “two spaces” never matches them, and they break a sort, a lookup or a comparison later on for no visible reason.
Blank lines get their own control because they are a different question from spaces. Collapsing runs down to one keeps paragraph structure while removing the double-spaced gaps a copy from an email client leaves behind. Removing them all is for a list. Leaving them alone is for anything where the blank lines are deliberate.
A paragraph copied out of a PDF
The report was published in March . It covered three regions .
The quick fix is the default mode: The report was published in March . It covered three regions .
Extra Spaces questions
Why does my text have two spaces after every full stop?
Because someone was taught to type that way. The two-space convention comes from monospaced typewriters, where every character was the same width and the extra space was the only way to make a sentence break visible. Proportional fonts have handled that spacing themselves for decades, so the second space now shows up as a visible gap, especially in justified text. Collapsing runs to one fixes the whole document in a single pass.
What is a non-breaking space, and why does find-and-replace miss it?
It is U+00A0, a different character from the ordinary space at U+0020 that renders identically but tells the layout engine never to break the line at that point. Web pages are full of them, so they come along with any copy. Because it is a separate character, searching for a space does not match it, which is why text that plainly has a gap in it refuses to be cleaned by hand. The “convert non-breaking and zero-width spaces” option rewrites them as normal spaces first, and drops the zero-width ones entirely.
Will this destroy the indentation in code I pasted?
Not if you choose “collapse runs but keep the leading indentation”. That mode leaves everything before the first non-space character on each line exactly as it was and only squeezes the runs that appear inside the line, so a Python block or a YAML file keeps its structure. The default mode does trim the front of each line, which is correct for prose and wrong for code.