Text cleaner
Collapses double spaces, trims line ends and removes repeated blank lines.
A quick tidy-up for text pasted from anywhere: extra spaces collapse to one, trailing spaces disappear and long runs of blank lines shrink to a single empty line.
Runs entirely in your browser. Your text is never uploaded — open DevTools, Network tab, and you will see zero requests while you use this tool.
How to use it
- Paste the text you want to tidy.
- Press Clean spacing.
- Copy the cleaned result.
What this tool does
Clean spacing normalises whitespace without touching a single word:
- Runs of two or more spaces or tabs collapse to one space.
- Whitespace at the end of every line is trimmed.
- Whitespace at the start of a line is trimmed, so pasted indentation disappears.
- Three or more consecutive blank lines become a single blank line.
- Line order, punctuation, capitalisation and the words themselves are left exactly as they were.
Two more buttons are on the same page because they are usually needed together: Join lines merges the text into one paragraph, and Remove duplicate lines strips repeated entries from a list.
Invisible characters that come from Word and the web
The visible mess is the easy part. The characters that cause real trouble are the ones you cannot see, and text pasted from Word, Google Docs, Outlook or a web page is full of them.
| Character | Where it comes from | What breaks |
|---|---|---|
| Non-breaking space (U+00A0) | Word autoformat, and copied from a web page | Looks like a space but is not one. A search for two words separated by a normal space finds nothing, and TRIM in Excel does not remove it. |
| Curly quotes ‘ ’ “ ” | Word and Docs autocorrect straight quotes as you type | Breaks code, CSV files, JSON and shell commands, which need straight ' and ". |
| En and em dashes – — | Autocorrect turns -- into a dash | Wrong in identifiers, filenames and command lines. |
| Zero-width space (U+200B) and zero-width joiner | Copied from web pages and CMS editors | Invisible, but consumes character-limit budget and defeats exact-match search. |
| Soft hyphen (U+00AD) | Hyphenation in Word and in HTML | Invisible until the word wraps, then a hyphen appears out of nowhere. |
| Byte order mark (U+FEFF) | The first character of many exported files | Corrupts the first column header of a CSV import. |
Carriage return (\r) | Windows line endings on a Unix system | Shows as ^M, and makes string comparisons fail for no visible reason. |
The pattern is always the same: two strings look identical on screen and refuse to match. Anywhere text is compared — a spreadsheet lookup, a database key, a find-and-replace, a deduplication — one invisible character makes the two values different. Cleaning whitespace first removes the most common source of that failure.
Examples
| Before | After Clean spacing |
|---|---|
Hello world | Hello world |
indented line | indented line |
| para one para two | para one para two |
a b (tabs) | a b |
A typical sequence for text pasted out of an email thread: Clean spacing to fix the whitespace, Remove duplicate lines to drop repeated quoted replies, then check the counters to see how much shorter it became.
When you need it
- Before importing a CSV. Trailing spaces in a key column turn one customer into two.
- Pasting into a CMS. Word formatting carried into an article shows up as odd spacing and inconsistent quotes in the published page.
- Preparing training or reference data. Consistent whitespace makes downstream processing predictable.
- Cleaning email threads. Forwarded messages arrive with ragged indentation and long runs of blank lines.
- Fixing OCR and scanned text. Recognition output is full of stray spaces around punctuation.
- Comparing two versions. A diff tool reports every trailing space as a change; cleaning both sides first shows only the real edits.
Doing it without this tool
- Microsoft Word:
Ctrl+H, tick Use wildcards, find{2,}and replace with a single space. For non-breaking spaces search for^s. To stop them coming back, turn off File → Options → Proofing → AutoCorrect → AutoFormat As You Type → Straight quotes with smart quotes. - Google Docs: Edit → Find and replace with Match using regular expressions, search
\s{2,}and replace with one space. Also Tools → Preferences to disable smart quotes. - Excel:
=TRIM(A1)collapses internal runs and trims the ends, but it does not remove non-breaking spaces — use=TRIM(SUBSTITUTE(A1,CHAR(160)," ")).=CLEAN(A1)strips non-printing control characters. - Notepad++: Edit → Blank Operations has Trim Trailing Space and Remove Empty Lines. Turn on View → Show Symbol → Show All Characters to see what is actually in the file, and Edit → EOL Conversion to fix line endings.
- Command line:
sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//' file.txtfor spacing,cat -A file.txtto reveal invisible characters, anddos2unix file.txtfor stray carriage returns.
Privacy: your text never leaves your browser
Cleaning is a set of regular expressions applied locally by JavaScript. No upload, no server processing, no storage, no account. Reload the page and the box is empty again.
People clean text precisely because it came from somewhere sensitive — an internal document, a customer export, an email thread. Keeping the processing on your device means the cleanup does not itself become a data disclosure.
Related tools
Frequently asked questions
Runs of spaces and tabs collapse to a single space, whitespace at the start and end of each line is trimmed, and three or more blank lines become one.
No. Only whitespace is touched. Letters, punctuation, capitalisation and line order stay exactly as they were.
Word inserts non-breaking spaces, curly quotes and em dashes automatically. They look normal but break code, CSV files and exact-match search.
It is a separate character (U+00A0) that renders like a space but never wraps. Search and TRIM in Excel do not treat it as whitespace, so identical-looking values fail to match.
Clean spacing only handles whitespace. To replace curly quotes, use find and replace in your editor, or turn off smart quotes in the AutoCorrect settings so they stop appearing.
Use =TRIM(A1) for ordinary spaces and =CLEAN(A1) for control characters. Non-breaking spaces need =TRIM(SUBSTITUTE(A1,CHAR(160)," ")).
Yes. The counters under the box update after every action, so you can see immediately how much shorter the text became.