Text guide
How to Clean Up and Format Messy Text (From PDFs, Emails and Websites)
Fix broken line breaks, double spaces, curly quotes, invisible characters and duplicate lines in text copied from PDFs, emails and web pages — in the right order.
By M2Toolkit Editorial TeamPublished 6 min read
Quick answer
Work in this order: 1) join broken lines, 2) remove extra spaces and invisible characters, 3) straighten curly quotes if the text is going into code or a spreadsheet, 4) remove duplicate or empty lines, and 5) fix capitalization. The Text Cleaner handles steps 2 and 3 in one pass.
Text copied from PDFs, emails, websites and Word documents rarely pastes cleanly. Lines break in the middle of sentences, spaces double up, and invisible characters sneak in that break searches, formulas and code. Each problem has a quick fix — the trick is doing them in the right order.
What goes wrong, and where it comes from
| Problem | Usually comes from | Fix with |
|---|---|---|
| A line break every few words | PDFs, emails | Remove Line Breaks |
| Double spaces, tabs | Word, PDFs, aligned text | Text Cleaner |
| Invisible characters | Websites, chat apps | Text Cleaner |
| Curly quotes “ ” breaking code | Word, macOS, phones | Text Cleaner |
| Repeated lines in a list | Exports, merged lists | Remove Duplicate Lines |
| ALL CAPS or random caps | Old systems, typing | Case Converter |
The order that works
- 1Join broken lines first. Keep paragraph breaks (blank lines) and rejoin words hyphenated across lines. If you clean spaces first, you can lose the paragraph structure you need.
- 2Remove extra spaces, tabs and invisible characters. Zero-width spaces and non-breaking spaces look like nothing but make “find” fail and break code.
- 3Straighten quotes when the text is going into code, CSV files or a terminal. Leave curly quotes in prose — they're typographically correct.
- 4Remove duplicate and empty lines in lists.
- 5Fix capitalization last, once the text is otherwise final.
The invisible characters worth knowing
- Non-breaking space (U+00A0): looks like a space, but formulas and searches treat it as different. Very common in text copied from websites.
- Zero-width space (U+200B): takes no space at all. It can make two identical-looking words fail to match.
- Soft hyphen (U+00AD): an invisible hint for where a word may break; it sometimes shows up as a stray hyphen.
- Byte-order mark (U+FEFF): appears at the start of some files and can break the first column of a CSV.
For anything else: find and replace with patterns
Regular expressions handle cleanups no preset covers. A few useful ones for the Find and Replace tool:
| Find | Replace with | Does |
|---|---|---|
\s+$ | (nothing) | Removes trailing spaces on each line (with multiline) |
^\d+\.\s* | (nothing) | Strips “1. ” numbering from a list |
(\w+)@(\w+) | $1 at $2 | Rewrites emails to deter scrapers |
\[\d+\] | (nothing) | Removes citation markers like [12] |
Frequently asked questions
Why does pasting from a PDF break every line?
PDFs store text as positioned lines, not paragraphs. When you copy, each visual line becomes a separate line. Joining lines while keeping blank-line paragraph breaks restores the original paragraphs.
Is it safe to paste private text into these tools?
Yes. M2Toolkit's text tools process everything in your browser, so the text never leaves your device.