Remove Extra Spaces
Remove Extra Spaces replaces every run of whitespace except carriage return and line feed with one ordinary space, then trims the complete result. Tabs, nonbreaking spaces, and repeated spaces inside lines collapse. Line breaks remain, although outer line breaks can disappear through trim. It does not trim each retained line independently or preserve tabs/semantic spacing.
Runs locally — files stay on your deviceAre line breaks preserved?
Interior CR/LF characters are preserved.
Horizontal whitespace and line boundaries are treated separately
The regex collapses characters that are whitespace but not CR or LF; this includes tabs and many Unicode spaces.
How it works
A global horizontal-whitespace-like regex writes one space, then String.trim removes outer whitespace.
Key concepts
Tabs collapse to one
Configured tab width is ignored.
Outer trim
Leading/trailing line breaks can be removed.
When to use it
- Clean repeated spaces inside prose lines.
- Replace tabs with a single space.
- Normalize copied horizontal spacing.
When not to use it
- Do not use on aligned tables or code.
- Do not expect line-by-line edge trimming.
- Do not preserve nonbreaking-space semantics.
Worked examples
Spaces
- Input
a b- Expected output
a b
Run collapses.
Tab
- Input
a\tb- Expected output
a b
Tab becomes one space.
Lines
- Input
a\n b- Expected output
a\n b
Line remains; indentation becomes one space.
Common mistakes
Using on tables
Alignment is destroyed. Correction: Use format-aware tooling.
Expecting indentation retained
Runs collapse. Correction: Avoid on code.
Assuming only ASCII space
Other horizontal whitespace changes. Correction: Inspect special spacing.
Best practices
- Use on prose, not structured layout.
- Preview tabs/nonbreaking spaces.
- Keep an original.
Related operations and differences
Remove Line Numbers
Choose Remove Line Numbers when you need to strip common line-number prefixes.; use Remove Extra Spaces specifically for remove extra spaces.
Trim Whitespace
Choose Trim Whitespace when you need to remove leading and trailing whitespace from lines.; use Remove Extra Spaces specifically for remove extra spaces.
Add Prefix to Every Line
Choose Add Prefix to Every Line when you need to add the same prefix before every line.; use Remove Extra Spaces specifically for remove extra spaces.
Add Suffix to Every Line
Choose Add Suffix to Every Line when you need to add the same suffix after every line.; use Remove Extra Spaces specifically for remove extra spaces.
Capitalize Every Word
Choose Capitalize Every Word when you need to capitalize the first character of every word.; use Remove Extra Spaces specifically for remove extra spaces.
Character Counter
Choose Character Counter when you need to count Unicode characters in text.; use Remove Extra Spaces specifically for remove extra spaces.
Limitations and privacy
- Collapse non-CR/LF whitespace and global trim only; no line-edge mode, tab-width control, nonbreaking-space preservation, format awareness, or change report.
Text is transformed locally in this browser and is not uploaded by the tool.
Frequently asked questions
Do tabs remain?
No.
Do interior line breaks remain?
Yes.
Are multiple spaces reduced to one?
Yes.
Is code formatting safe?
No.