How to Remove Line Breaks From Text (Copied From PDF or Email)
Join broken lines from a PDF or email into clean paragraphs with find and replace. Patterns to remove all line breaks or keep paragraph gaps, with examples.
The short answer
To remove line breaks from text, open the Find and Replace Text tool, paste your text, tick Use regex, type \n in Find, type a single space in Replace with, and keep Replace all ticked. Every line break becomes a space and the text joins into one paragraph. If you want to keep the gaps between paragraphs and only fix the broken lines inside them, use ([^\n])\n(?=[^\n]) in Find and $1 (dollar, one, space) in Replace.
Why text copied from a PDF or email breaks into short lines
PDFs, emails and some websites store each visual line of text as a separate line. When you copy from them, you get a hard line break at the end of every line, even in the middle of a sentence:
This is a line copied from a PDF that
breaks in the middle of a sentence and
continues here.
Pasted into a document, form or chat, that text keeps its odd short lines. Fixing it by hand means deleting each break and adding a space, which is slow and easy to get wrong.
Method 1: join everything into one paragraph
Use this when the text is a single paragraph, or when you do not care about paragraph breaks.
\n (a backslash followed by the letter n). This means "line break" in a regular expression.The match counter tells you how many line breaks were found. For the three-line example above, the tool finds 2 and produces one clean sentence.
Important: the backslash pattern only works with Use regex ticked. Without it, the tool looks for the two characters backslash and n, and finds nothing.
Method 2: keep paragraphs, fix the lines inside them
Most copied documents have several paragraphs separated by a blank line. Method 1 would merge them all into one block. To keep the blank lines:
- Find:
([^\n])\n(?=[^\n]) - Replace with:
$1(dollar sign, the digit 1, then a space) - Use regex: ticked
- Replace all: ticked
How it works, piece by piece:
| Part | Meaning |
|---|---|
| ([^\n]) | Any character that is not a line break, captured as group 1 |
| \n | The line break you want to remove |
| (?=[^\n]) | Only if the next character is also not a line break |
| $1 followed by a space | Put the captured character back, then add a space |
A single line break between two pieces of text is replaced by a space. A blank line (two line breaks in a row) does not match, so paragraph gaps survive.
Example input:
This is a line copied from a PDF that
breaks in the middle of a sentence and
continues here.
(blank line)
Second paragraph starts
here and ends here.
Result: two paragraphs, each on one line, with the blank line between them kept.
More clean-up patterns
These all use Use regex and Replace all. Each one was tested with the tool's own matching logic.
| Problem | Find | Replace with |
|---|---|---|
| Turn a list into one comma-separated line | \n | , (comma and space) |
| Remove spaces left at the ends of lines when joining | *\n * | one space |
| Text with Windows line endings | \r?\n | one space |
| Squeeze runs of 3 or more line breaks down to one blank line | (\n\n)\n+ | $1 |
| Collapse double or triple spaces | {2,} | one space |
| Rejoin words split by a hyphen at a line end | -\n | nothing (leave empty) |
Notes on these:
- List to one line: "one", "two", "three" on separate lines becomes "one, two, three".
- Windows line endings:
\r?\nmatches both kinds of line break, so it is a safe choice if you are not sure where the text came from. For the paragraph-keeping pattern, the equivalent is([^\r\n])\r?\n(?=[^\r\n])with$1as the replacement. - Blank-line squeeze: this works because
$1puts back the two line breaks it captured. - Hyphen rejoin: check the result. Real hyphenated words that happen to fall at a line end, such as "well-known", will lose their hyphen too.
The one thing this tool cannot do: add new line breaks
The Replace with box is a single-line field, and typing \n into it inserts the two characters backslash and n, not a line break. So you can remove line breaks, but you cannot use it to split "a, b, c" into separate lines.
The only way to put line breaks back is the $1 trick above, which re-inserts line breaks that were captured from the original text. For splitting a comma-separated list into lines, a spreadsheet's text-to-columns feature or a code editor is a better fit.
Troubleshooting
- "0 matches found". Check that Use regex is ticked. Also check the text actually has line breaks and is not just wrapping visually in the box.
- An error message appears under the options. The pattern has a typo, such as an unclosed bracket. The tool shows the error from the regular expression engine and leaves your text unchanged until it is fixed.
- Words run together. You replaced the line break with nothing instead of a space. Put a single space in Replace with.
- Only the first break was replaced. Tick Replace all.
- Double spaces after joining. The original lines ended with spaces. Use the
*\n *pattern, or run the double-space pattern afterwards.
Common mistakes
- Typing
/ninstead of\n. It must be a backslash. - Using Method 1 on multi-paragraph text and then having to split paragraphs again by hand. Use Method 2.
- Ticking Whole word with regex patterns for line breaks. Whole word wraps the pattern in word boundaries, so line breaks after punctuation (for example after a full stop) stop matching. Leave it unticked for these patterns.
- Forgetting to check the result before pasting. Read the first few lines of the output, especially if the text has headings or lists that should keep their own lines.
Related tools and guides
- Capture groups, whole words and more regex examples: Find and Replace With Regex
- Removing repeated lines after cleaning a list: Remove Duplicate Lines
- Checking the length of the cleaned text: Word Counter
Frequently asked questions
How do I remove all line breaks from text?
In a find and replace tool with regex turned on, find \n and replace it with a single space, with Replace all ticked.
How do I remove line breaks but keep paragraphs?
Find ([^\n])\n(?=[^\n]) and replace with $1 followed by a space, with regex on. Single line breaks become spaces and blank lines between paragraphs stay.
Why does searching for \n find nothing?
Regex mode is off. Without it the tool looks for a literal backslash and the letter n. Tick Use regex.
Can I replace commas with line breaks in this tool?
No. The Replace with box cannot insert new line breaks; typing \n there inserts the characters backslash and n.
Put this guide into practice with our free online tool — no signup required.
Open tool