01What is Remove Extra Spaces?
Remove Extra Spaces fixes uneven spacing inside lines of text. Copy text out of a justified PDF, an OCR scan or a Word document and you often get runs of spaces, tabs or non-breaking spaces where one space should be. They look harmless, but they break exact string comparisons and make data hard to de-duplicate. The tool works line by line. It splits your input on line breaks, accepting both LF and CRLF. Then, in each line, it replaces any run of two or more horizontal whitespace characters with a single ordinary space. The code uses the pattern [^\S\r\n]{2,}. In plain words, that's any whitespace character that isn't a line break, two or more times in a row. Whitespace here means JavaScript's \s class as defined in the ECMAScript spec. It covers the space, tab, non-breaking space (U+00A0), the thin space (U+2009) and the other Unicode space separators. A single tab or a single non-breaking space on its own is left alone. Only runs are collapsed. Mixed runs count too, so a non-breaking space next to a normal space becomes one normal space. The Trim Lines option is on by default. It also removes all whitespace from the start and end of every line. Turn it off and leading or trailing runs still shrink to one space, but they don't disappear. Line breaks are never touched. Blank lines stay where they are, and if your input contains CRLF the output keeps CRLF. Here is a worked example. Paste " indented line " with Trim Lines on and you get "indented line". The Whitespace Removed counter reads 6, since the line went from 19 characters to 13. With Trim Lines off the result is " indented line ", with one space left at each end, and the counter reads 4. Your text stays in the browser tab. The cleanup is a couple of string replacements run by the page, with nothing sent to a server. A few honest limits. Indentation doesn't survive. With Trim Lines on it is removed, and with it off it shrinks to one space, so keep Python, YAML and Makefiles away from this tool. Zero-width characters such as U+200B are not whitespace under JavaScript's rules, so they stay in. And because Whitespace Removed is just the length difference, it counts UTF-16 code units, not visible gaps.
Developers and data cleaners who paste text from PDFs, OCR or web pages and need runs of spaces, tabs and non-breaking spaces reduced to single spaces before comparing or storing it. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Remove Extra Spaces
- Paste your text into the Input Text box.
- Leave Trim Lines ticked to strip whitespace from both ends of each line, or untick it to keep one space there.
- Read the cleaned text in the Output box. It updates as you type.
- Check Whitespace Removed, Original Length and New Length to see how much changed.
- Copy the result with the button next to Output, or press Reset to start over.
03Worked examples
- Input:
Hello world - Result:
Hello world - Five spaces collapse to one. Whitespace Removed shows 4.
- Input:
" indented line " with Trim Lines on - Result:
"indented line" - Ends are trimmed and the inner run collapses. 19 characters down to 13.
- Input:
" indented line " with Trim Lines off - Result:
" indented line " - The runs at each end shrink to one space instead of disappearing.
- Input:
a[tab][tab]b - Result:
a b - A run of tabs becomes one plain space, not one tab.
- Input:
a[non-breaking space][space]b - Result:
a b - Mixed runs count, so U+00A0 plus a space becomes one ordinary space.
- Input:
x y\n\n z (Trim Lines on) - Result:
x y\n\nz - The blank line in the middle is kept. Only spaces inside lines change.
04Common use cases
- Cleaning text copied from a justified PDF, where each line is padded with runs of spaces
- Normalizing names or addresses before comparing or de-duplicating them, so "Jane Doe" equals "Jane Doe"
- Fixing double spaces after full stops in an old document before publishing it
- Tidying OCR output where gaps between words come out as several spaces or tabs
- Replacing non-breaking spaces copied from a web page that make a search or exact match fail
- Stripping leading and trailing spaces from each line of a pasted list with Trim Lines on
05Tips
- Non-breaking spaces look exactly like normal ones. If two strings 'look equal' but don't compare equal, run both through here.
- This tool keeps blank lines. Follow it with Remove Blank Lines if you want those gone too.
- A single tab between two words stays a tab. Only runs of two or more characters get replaced.
- In your own JavaScript, s.replace(/[^\S\r\n]{2,}/g, ' ') gives the same collapse while leaving line breaks alone.
06Related concepts
Unicode whitespace, Text normalization, Non-breaking space, String trimming.
Frequently Asked Questions
What is Remove Extra Spaces?
Remove Extra Spaces is a free, browser-based developer tool on AIDToolStack. Remove extra whitespace and normalize spacing in text. It requires no installation or sign-up and works entirely in your browser.
Is Remove Extra Spaces free to use?
Yes. No sign-up, no fees and no usage cap.
Does Remove Extra Spaces store my data?
No. It runs in your browser; nothing is uploaded.