A practical walkthrough of cleaning messy text online — handling whitespace, line breaks, HTML tags and stray characters.
Step-by-step guide to cleaning text online: removing extra spaces, line breaks, HTML tags and unwanted characters.
Key points from this guide
Whitespace problems come in three kinds: repeated spaces, trailing spaces at line ends, and hard line breaks inside paragraphs — each needs a different fix.
Non-breaking spaces (U+00A0) pasted from web pages and Word look identical to normal spaces but break search and comparison; collapsing whitespace removes them.
De-duplication is exact and case-sensitive, so lowercase and trim the list first or near-identical entries survive.
Stripping HTML tags removes the markup but not the entities, so & and may remain in the output.
Clean in the browser when the text is confidential: nothing needs to be uploaded to fix whitespace.
Frequently asked questions
How do I turn PDF text back into paragraphs?
Remove line breaks to rejoin the lines, then remove extra spaces to fix the doubled spacing at the joins. Watch for words hyphenated across the original line breaks.
Why do my duplicate lines survive de-duplication?
They differ by case or by a trailing space. Lowercase the list and remove extra spaces first, then de-duplicate.