Text Cleaner — Remove Line Breaks, Extra Spaces & Duplicate Lines
Remove line breaks, extra spaces, duplicates and invisible characters, sort lines, and find and replace, in one pass.
10 lines · 114 characters
6 lines · 78 characters
Changes: 2 tags removed · 1 invisible character removed · 2 curly quotes straightened · 2 lines trimmed · 3 runs of extra spaces collapsed · 3 empty lines removed · 2 duplicate lines removed
Runs entirely in your browser. Nothing you paste is sent to us or stored. Browse all free tools.
Found a problem, or something that could be better? We read every message and we fix things quickly.
This free text cleaner fixes the mess that comes with copied text: line breaks in the middle of sentences from a PDF, double spaces, blank lines, duplicate entries in a list, curly quotes that break code, leftover HTML tags, and invisible zero-width characters that make two identical-looking strings unequal. Tick the steps you need and they all run together, live, as you paste.
Every step reports what it changed, for example “3 duplicate lines removed” or “2 invisible characters removed”, so you can see that the tool did what you expected rather than trusting a black box. Steps run in a fixed order: character cleanup first, then line operations such as dedupe and sort, then find and replace last. For one-off edits that is all you need; for a cleanup you repeat every week on exported data, a short script will serve you better, and the regex you test here can go straight into it.
How to use
- Paste your text into the Input box. The sample shows a messy list being cleaned.
- Tick the cleanup steps you want. Character steps (HTML, invisible characters, quotes, line breaks, spaces) run first.
- Choose line operations: remove empty or duplicate lines, sort, reverse or shuffle.
- Optionally fill in Find and Replace with. Tick Regular expression to use patterns and $1-style capture groups.
- Check the Changes line to see what was done, then copy or download the cleaned output.
Frequently asked questions
How do I remove line breaks from text copied from a PDF?
Paste the text and tick Remove line breaks, with Keep paragraphs on. PDFs store each visual line separately, so copied text has a break at the end of every line; this joins the lines of each paragraph with a space and keeps the blank lines between paragraphs. Turn on Collapse repeated spaces too, since PDFs often leave double spaces behind.
How do I remove duplicate lines?
Tick Remove duplicate lines. The first occurrence of each line is kept and later copies are removed, so the order of the remaining lines does not change. Tick Ignore case to treat “Apple” and “apple” as the same. Trim lines is on by default, so lines that differ only by trailing spaces also count as duplicates.
What are zero-width characters and why remove them?
They are Unicode characters with no visible width, such as the zero-width space (U+200B), zero-width joiner (U+200D), the byte order mark (U+FEFF) and the soft hyphen (U+00AD). They come in from web pages, chat apps and word processors, and they make strings that look the same compare as different, break search, and cause errors in code and spreadsheets. The cleaner removes them and turns non-breaking and other unusual spaces into normal spaces.
What is natural sort?
Natural sort compares numbers inside text by their value instead of character by character. A plain A–Z sort puts file10 before file2, because the character 1 comes before 2; natural sort gives file1, file2, file10, which is what people expect. Numeric sort instead orders lines by the first number found in each line and puts lines with no number at the end.
Can I use regular expressions in find and replace?
Yes. Tick Regular expression and the Find field is read as a JavaScript regex with the global, multiline and Unicode flags, so ^ and $ match at each line (plus case-insensitive unless Match case is on). Use $1, $2 for capture groups and $& for the whole match in the replacement, and \n for a newline. If the pattern is invalid, the error is shown instead of the output changing.
The order steps run in, and why
1. Strip HTML runs first, because tags and entities hide the real text. Block tags such as </p> and <br> become line breaks so paragraphs survive; scripts, styles and comments are removed with their content.
2. Invisible characters and smart quotes are next, so that later steps compare clean text. Two lines that differ only by a zero-width space become true duplicates.
3. Remove line breaks, trim and collapse spaces reshape the text.
4. Empty-line removal, deduplication, sorting, reversing and shuffling work on the lines that result.
5. Find and replace runs last, on the cleaned text, so your pattern does not have to account for stray spaces or invisible characters.
Useful regex replacements
• Reformat dates from 2026-10-16 to 16/10/2026: find (\d{4})-(\d{2})-(\d{2}), replace with $3/$2/$1.
• Add a prefix to every line: find ^ and replace with - (dash and space). ^ and $ match at the start and end of each line.
• Remove everything after the first tab on each line: find \t.*$ and leave Replace empty.
• Turn a column into a comma-separated list: find \n and replace with , (comma and space).
• Wrap each line in quotes for an SQL IN list: find ^(.+)$ and replace with '$1', then join the lines as above.
• Remove footnote markers such as [12]: find \s*\[\d+\] and leave Replace empty.
Related free tools
- Case Converter — Switch text between twelve cases in one click, from UPPER and Sentence case to camelCase, snake_case and kebab-case.
- Diff Checker — Compare two versions of a text, code or JSON file and see exactly which lines, words and characters changed.
- Word Counter — Count words, characters, sentences and reading time, and check X, LinkedIn, Instagram, YouTube, SEO and SMS limits as you type.
- Regex Tester — Test a regular expression against sample text with live match highlighting, capture groups and replace preview. Free, in your browser.