Remove extra spaces from text

Remove extra spaces from text by collapsing every run of two or more spaces into a single space, with an optional cap on how many consecutive blank lines you keep. Tabs are left alone, line endings stay LF or CRLF as you pasted them, and the transform fires on every keystroke in your browser. Need the inverse? Send your text through repeat text or insert padding with left pad.

Input
Line 1:1 LF cloud_done Saved locally
Result Remove Extra Spaces
0 lines 0 chars

How extra-space removal works

The cleaner walks the input with a regular expression that matches two or more consecutive ASCII spaces, then writes back exactly the number of spaces you asked for. The default cap is one, so any run of 2, 5, or 50 spaces collapses to a single space. Tabs (\t) and other whitespace characters are not touched, so a tab between columns survives the pass even when nearby double-spaces are squeezed.

Newline collapsing is a separate, opt-in pass. Toggle Newlines on and any run of \n or \r\n longer than the Max Newlines value collapses to that many line breaks. Leave it off and your blank lines pass through untouched, which is what you want when blank lines carry meaning (paragraph breaks in prose, separators in logs).

Everything runs in the browser via JavaScript. No upload, no log, no round trip. The output panel updates as you type, and the input status bar shows the line ending so you can confirm CRLF stayed CRLF after the transform. For stripping every space rather than collapsing runs, switch to remove all whitespace; for trimming only the ends of each line, see trim whitespace.

How to use remove extra spaces from text

  1. 1Paste or type your text into the input panel on the left.
  2. 2Confirm the Spaces toggle is on and read the live result on the right.
  3. 3Adjust Max Spaces if you want to keep up to 2 or 3 spaces between words.
  4. 4Turn on Newlines and set Max Newlines to cap consecutive blank lines.
  5. 5Click Copy in the output header to grab the cleaned text.

Keyboard shortcuts

Drive TextResult without touching the mouse.

Shortcut Action
Ctrl FOpen the find & replace panel inside the input Plus
Ctrl ZUndo the last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor Plus
EscClose find & replace, or exit fullscreen
Ctrl KOpen the command palette to jump to any tool Plus
Ctrl SSave current workflow draft Plus
Ctrl PRun a saved workflow Plus

What this tool actually does

Collapses runs of spaces, not all whitespace

The regular expression / {2,}/g only matches the ASCII space character. Tabs, non-breaking spaces, em spaces, and other Unicode whitespace pass through untouched. If you want every kind of whitespace gone, use remove all whitespace instead.

Configurable cap on space runs

The Max Spaces field accepts 1 to 20. A value of 1 turns every run into a single space, the standard typographic outcome. A value of 2 lets double-spaces survive, useful for fixed-width tables where double-space is a column separator.

Optional blank-line collapsing

Flip the Newlines toggle on to collapse runs of line breaks. The match handles both \n and \r\n, and the Max Newlines field caps how many survive. Leave the toggle off and paragraph breaks pass through as-is.

Tabs and other whitespace preserved

Tab characters are skipped by the space regex, so columns indented with tabs stay aligned. To convert tabs to spaces first, run tabs to spaces before this tool, or to go the other way use spaces to tabs.

Runs in your browser, no upload

The transform is a single String.replace call evaluated locally on every keystroke. Nothing leaves the page, no copy of your text is logged, and the output panel updates without a server round trip.

Worked example

Default settings collapse space runs to one. The four blank rows pass through because Newlines is off.

Input
The   quick    brown   fox     jumps  over the lazy dog.



Final line
Output
The quick brown fox jumps over the lazy dog.



Final line

Settings reference

Setting or behaviour Effect on output
Spaces toggle (default on) When on, runs of 2+ ASCII spaces collapse. Turn off to bypass space collapsing entirely.
Max Spaces (default 1) Caps how many consecutive spaces survive. 1 leaves single spaces, 2 keeps double-spacing, up to 20.
Newlines toggle (default off) When on, runs of line breaks collapse. When off, blank lines pass through unchanged.
Max Newlines (default 1) Caps consecutive line breaks when the newlines toggle is on. 1 removes all blank rows, 2 keeps single blank rows.
Tabs Always pass through. Use tabs to spaces if you want them converted first.
Non-breaking and exotic whitespace Pass through. Use remove all whitespace for full Unicode whitespace stripping.
Line endings LF stays LF, CRLF stays CRLF. The input status bar shows which is in play.

FAQ

Does it remove tabs as well as spaces?
No. By default only the ASCII space character is collapsed. Tabs, non-breaking spaces, and other Unicode whitespace pass through. If you want every kind of whitespace gone, use remove all whitespace with the All mode.
Can I keep double spaces between sentences?
Yes. Set Max Spaces to 2. Any run of two or more spaces will be capped at two, so single and double spacing both survive. Set it to 3 if you have a fixed-width format that uses triple spaces as a column separator.
Why are my blank lines still there?
Blank-line collapsing is a separate toggle. Turn on Newlines to collapse runs of line breaks, then set Max Newlines to the number you want to keep. Default behaviour leaves blank lines alone so paragraph breaks survive.
Is the input sent to a server?
No. Every transform runs locally in your browser as a JavaScript regex replacement. Nothing is uploaded, nothing is logged, and there is no record of your text on our side.
What if I want to remove every space, not just extras?
Use remove all whitespace. That tool deletes every space, tab, and newline rather than collapsing runs. You can also pick a mode there to remove just spaces, just tabs, or just newlines.