Toolyard

How to Remove Line Breaks From Text

Why it happens

A PDF stores each line of a page separately, so copying a paragraph gives you a line break wherever the page wrapped. Plain-text emails do the same at about 70 characters.

Join every line

Paste the text into Find and Replace and tick Regular expression. Find \s*\n\s* and replace it with a single space. Every line break and the spaces around it become one space.

Keep the paragraphs

Usually paragraphs are separated by an empty line, and you only want to join the lines inside them. With Regular expression ticked, find (?<!\n)\n(?!\n) and replace it with a space. That matches a line break only when there is no other line break right before or after it, so empty lines between paragraphs stay.

Fix the hyphens

If words were split across lines, such as exam- and ple, first find -\n and replace it with nothing. Check the result for real hyphenated words, such as well-known, that happened to fall at the end of a line.

Other clean-ups

Find {2,} (a space followed by {2,}) and replace it with one space to remove double spaces. To drop repeated lines, use Remove Duplicate Lines, and check the length afterwards with the Word Counter.

Tools in this guide

More guides