Remove Extra Spaces
Collapse repeated spaces, trim lines and strip blank lines or invisible characters.
Remove Extra Spaces tool
Invisible characters
Characters you cannot see but a string comparison can. They arrive from PDFs, word processors and copied web pages, and they are why two identical-looking lines refuse to match.
Whitespace
What changed
What this tool does
Seven whitespace operations, each with its own switch, applied in a fixed order and previewed live as you type: collapse repeated spaces, trim lines, drop blank lines, convert tabs either way, normalise line endings, trim the document. Each run reports what it changed.
The two switches at the top are why most people arrive here. They remove characters that are genuinely invisible — zero pixels wide — and replace the space-like characters that are not the ordinary space you typed.
Common uses
- Fixing a CSV that will not import because half its fields carry a trailing space.
- Repairing text pasted out of a PDF, which arrives with soft hyphens mid-word and non-breaking spaces around every unit.
- Making two lists comparable before a diff, so it reflects content and not formatting.
- Normalising indentation across a file edited in three editors with three tab settings.
A short example
This line looks like an ordinary amount with ordinary spaces in it:
Total: 1 240,00 EUR
It is not. The space after Total: is U+00A0, the one inside the number is
U+202F, and a U+200B sits just before EUR. parseFloat returns
NaN and trim() does not help, because none of the three is what a
plain space-trim looks for. With both invisible-character switches on, the line comes back
as ordinary tokens separated by ordinary spaces, and the report names what it removed.
The characters you cannot see
"Strip zero-width characters" removes six code points, each with its own way of ruining an afternoon:
- U+200B zero-width space. A line-break hint inserted by web editors. Makes two visually identical strings unequal.
- U+200C, U+200D and U+2060. The joiners — legitimate in Persian, Hindi and emoji, pure noise anywhere else.
- U+00AD soft hyphen. Invisible until the line wraps. PDF extraction scatters these through words.
- U+FEFF byte-order mark. A BOM at the start of a file breaks JSON parsing, shell scripts and CSV headers, with an error that never mentions it.
"Normalise non-breaking spaces" converts nine space-like characters to a plain U+0020, including U+00A0, the ideographic space U+3000 that Japanese input methods produce, and the narrow, figure, thin, hair, en and em spaces.
Worth knowing
U+200D, the zero-width joiner, is the same character that binds 👨👩👧👦 into one family emoji. Strip it blindly and the family becomes four separate people. "Keep emoji sequences intact" is on by default and protects a joiner between two pictographs while removing every other one — which no find-and-replace can do for you.
Order is fixed: invisible characters first so later steps see real spaces, then tab conversion, then per-line trimming, then blank-line removal. Trimming before stripping a non-breaking space leaves the space behind — precisely the bug that makes people think their editor's "trim trailing whitespace" is broken.
Frequently asked questions
Why doesn’t trim() or \s remove these characters?
Coverage varies by language and by character. JavaScript’s trim() and \s do match U+00A0 and U+FEFF, but never U+200B, which Unicode 4.0.1 reclassified from a space to a format character. Java’s and Go’s \s are ASCII-only, and PCRE’s is too unless Unicode property support is switched on. Check the behaviour you are counting on in the regex tester before shipping it.
How do I find out which invisible character is in my string?
Dump the code points. In JavaScript, [...s].map(c => c.codePointAt(0).toString(16)) prints them; on a file, hexdump -C does. VS Code flags them in the editor too — editor.unicodeHighlight.invisibleCharacters has been on by default since version 1.63, which is why a pasted string sometimes shows a yellow box around apparently nothing. The panel above names each one it finds in your text.
Why does a non-breaking space come back every time I edit the text?
Rich-text editors insert them on purpose. HTML collapses a run of whitespace to a single space, so a contenteditable field that has to preserve a double space writes U+00A0 as the second one — Google Docs, Slack and most CMS editors all behave this way. French typographic rules add more, putting a space before ; : ! and ?. Clean the text where it leaves the editor, not before.