belun.app Blog

Whitespace Remover — Delete Extra Spaces and Blank Lines

Default run: runs of spaces and tabs collapse to one, every line is trimmed, repeated blank lines merge into one — and 22 invisible Unicode characters that Excel's TRIM() and a plain \s regex both leave behind are stripped out. Single spaces and line breaks are kept.

every character it removes ↓ · the same job in code ↓

Cleaning rules
Characters
0 → 0
Lines
0 → 0
Words
0 → 0
Removed
0 0%
Download .txt

Paste messy text and get a clean copy back. The tool collapses repeated spaces, trims every line, drops or merges blank lines, and clears out non-breaking spaces and zero-width characters that survive a copy-paste from Word or a PDF. Live before/after counts show exactly how much was stripped.

Every character this tool removes

Fifteen rows, 22 code points. The \s column is the reason most hand-written cleanups fail: five of these characters are not whitespace as far as a JavaScript regex is concerned, so they survive every replace(/\s+/g, "") you throw at them.

Code point Name Where it comes from Matched by \s What happens here
U+0020 Space The space bar yes Runs of two or more collapse to one
U+0009 Tab Tab key, terminal output, code pasted out of an editor yes Collapsed with surrounding spaces, or converted to a single space on request
U+000A · U+000D Line feed · carriage return Enter; CRLF from Windows and Outlook yes CRLF normalised to LF. Line breaks are kept unless you ask for them to go
U+00A0 No-break space Word,   in HTML, almost any PDF copy-paste yes Replaced with a plain space
U+2000–U+200A Quad, en, em, thin and hair spaces (11 characters) Typesetting, InDesign, LaTeX output, PDFs yes Replaced with a plain space
U+202F Narrow no-break space French typography, dates, currency amounts yes Replaced with a plain space
U+205F Medium mathematical space MathML and formula editors yes Replaced with a plain space
U+3000 Ideographic space Full-width Japanese, Chinese and Korean text yes Replaced with a plain space
U+1680 Ogham space mark Legacy Irish text yes Replaced with a plain space
U+180E Mongolian vowel separator Legacy text — reclassified as a format character in Unicode 6.3 no Replaced with a plain space
U+200B Zero-width space CMS exports and line-break hints in HTML no Deleted
U+200C Zero-width non-joiner Persian, Arabic and Hindi text no Deleted
U+200D Zero-width joiner The glue inside multi-part emoji; Indic scripts no Deleted — see the emoji caveat below
U+2060 Word joiner Hand-authored HTML, the modern replacement for U+FEFF no Deleted
U+FEFF Byte-order mark The first character of a UTF-8 file, carried along by a copy yes in JS, no in Python Deleted

One invoice line, seven separate problems

A four-line block copied out of a PDF invoice, run through the default rules. Nothing in the left column is visible on screen — which is exactly why it survives a manual cleanup.

In the paste What it is What the tool did
Invoice␣␣No. Two spaces after a word Collapsed to one
No.⟨U+00A0⟩␣2026 No-break space from the PDF Became a space, then collapsed
␣␣␣Client: Three-space indent Trimmed off the line
Acme⟨U+200B⟩␣Ltd. Zero-width space mid-name Deleted
(blank)(blank) Two blank lines in a row Merged into one
Total:⟨TAB⟩⟨U+2009⟩1 Tab plus a thin space Both became spaces, then collapsed
240,00⟨U+202F⟩€ Narrow no-break space before the currency Became a plain space

74 characters in, 58 out — 16 removed, 21.6% of the block. Ten words before, ten words after: nothing but air was lost. The counters under the tool report the same four numbers for your own text.

The same job in code

If you are cleaning one column rather than one document, do it where the data lives. The third column is the part nobody writes down — what each of these still misses.

Where What to run What it still misses
JavaScript
s.replace(/[^\S\n]+/g, " ")
s.replace(/\s+/g, "")
U+200B, U+200C, U+200D, U+2060 and U+180E are not in JavaScript's \s
Python
" ".join(s.split())
re.sub(r"\s+", " ", s).strip()
U+200B–U+200D, U+2060 and U+FEFF are not whitespace to Python
Excel
=TRIM(A1)
Only the ASCII space, character 32. Tabs, line breaks and every Unicode space survive — this is why TRIM appears to do nothing on data copied from a website
Excel, the version that works
=TRIM(SUBSTITUTE(CLEAN(A1), CHAR(160), " "))
CLEAN drops characters 0–31 and SUBSTITUTE kills the no-break space, but the other Unicode spaces still get through
Google Sheets
=REGEXREPLACE(TRIM(A1), "\s+", " ")
Sheets uses RE2, whose \s is ASCII-only — the same gaps as Excel
PostgreSQL
btrim(regexp_replace(s, '\s+', ' ', 'g'))
Unicode spaces are not reliably covered; add translate(s, U&'\00A0', ' ') first
Shell
sed -E 's/[[:space:]]+/ /g; s/^ +| +$//g'
awk '{$1=$1};1'
[[:space:]] is ASCII in the C locale, and so is awk's default field split
VS Code · Word
VS Code: find " {2,}" with regex on, replace with one space
Word: Use wildcards, "[ ]{2,}" → one space; "^s" finds a no-break space
Neither finds zero-width characters unless you paste the literal character into the search box

To catch everything in one pass, add the five zero-width characters explicitly: s.replace(/[\s\u200b-\u200d\u2060\ufeff\u180e]+/g, " ").trim() . That is the pattern this page runs, split into two steps so the spaces become spaces and the zero-width characters disappear instead of becoming spaces.

How it works

  1. 1
    Paste your text Drop the text into the left box. Cleaning runs as you type, so there is no button to press and nothing to wait for.
  2. 2
    Pick the rules Toggle the checkboxes: collapse repeated spaces, trim each line, remove or merge blank lines, convert tabs, or strip every whitespace character at once.
  3. 3
    Copy the result The cleaned text appears on the right along with the character, word, and line counts before and after. Copy it to the clipboard or download it as a .txt file.

Your data stays private

All processing happens entirely in your browser. No files, text, or data are ever sent to our servers. You can disconnect from the internet and this tool will still work.

Frequently asked questions

What counts as whitespace?
Regular spaces, tab characters, and line breaks. This tool also handles the invisible lookalikes: non-breaking spaces (U+00A0), en and em spaces, the ideographic space used in Japanese text, zero-width joiners, and byte-order marks. The table above lists all 22 code points.
Why does my text have spaces I cannot see?
Copying from Word, Google Docs, or a PDF often brings along non-breaking spaces instead of regular ones. They look identical but break search, sorting, and CSV parsing. Leave the Unicode normalisation option on and they get converted to plain spaces.
Does a s regex catch every invisible space?
No, and this is the single most common reason a hand-written cleanup leaves the text still broken. JavaScript's s misses U+200B, U+200C, U+200D, U+2060 and U+180E. Python's s misses those plus the byte-order mark U+FEFF. Java, Google Sheets and sed go further and match ASCII whitespace only, so even a plain non-breaking space gets through.
Why does Excel's TRIM leave the spaces in place?
TRIM only removes character 32, the ASCII space. Text pasted from a web page or a PDF is usually padded with character 160, the non-breaking space, which TRIM ignores completely. Use =TRIM(SUBSTITUTE(CLEAN(A1), CHAR(160), " ")) instead, or paste the column here and copy the cleaned version back.
How do I remove extra spaces but keep the line breaks?
That is the default here: Collapse repeated spaces and Trim each line are on, Remove all whitespace is off. Runs of spaces and tabs inside a line collapse to one, every line loses its leading and trailing padding, and the line structure survives untouched.
Does it keep my paragraphs?
Yes, by default. Single line breaks stay untouched and runs of blank lines collapse to one, so paragraph structure survives. Turn on Remove empty lines if you want everything packed together with no gaps.
Can I remove every space in the text?
Yes. Switch on Remove all whitespace and the result is one unbroken string with no spaces, tabs, or line breaks. That setting overrides the other rules, which grey out while it is active.
What is the difference between this and a line break remover?
This tool works inside the lines: it collapses spaces, trims the ends, and merges blank lines, while keeping the line structure. A line break remover joins the lines themselves back into flowing paragraphs, which is what you want for text pasted out of a PDF column or a hard-wrapped email.
Will cleaning invisible characters break my emoji?
It can. Multi-part emoji are built from a zero-width joiner (U+200D), so stripping invisible characters turns a single 👩‍💻 into two separate pictures. Untick Fix invisible Unicode spaces if the text contains emoji like that; every other rule is safe for them.
Is there a size limit?
No hard limit is enforced. Processing happens in your browser, so very large documents (a few megabytes and up) depend on your device's memory rather than any server quota.
Is my text sent anywhere?
No. Everything runs in JavaScript inside this page. Your text never reaches a server, which makes it safe for contracts, medical notes, and anything else you would rather not paste into a cloud service.

From the blog

Extra Spaces in Text: Where They Come From and How to Strip Them Why pasted text is full of double spaces and invisible characters, and how to clean it in a few seconds. Read the post →

Related tools