Collapse Whitespace
Collapse runs of spaces or tabs to one space and reduce three or more consecutive newlines to two.
How to use
- Enter irregularly spaced text and run the normalization.
Capabilities and scope
Horizontal whitespace and excessive blank lines use separate normalization rules, followed by trimming the whole result.
How it works
/[\t ]+/g becomes one space, /\n{3,}/g becomes two newlines, and the final string is trimmed.
Example
a b c becomes a b c.
Useful for
- Clean excessive spacing in copied plain text
Before you use it
- Two newlines are intentionally preserved as a paragraph separator and not every Unicode whitespace character is covered by the horizontal rule.
Frequently asked questions
Are all line breaks collapsed to one?
No. Runs of three or more become two so one blank line between paragraphs remains.