Having broken lines is not uncommon when editing documents in word processors like MS Word and Google Docs. The most common cause behind the separated lines is usually from copying and pasting text from sources in a different format.
Regardless, pasting the content without formatting (i.e. in plain text) is not guaranteed to help this situation other than remove any text formatting applied to the source (e.g. fonts, italics or bold).
So how does one combine the multiple lines without resorting to time-consuming manual edits? Well, the answer lies in the Find and Replace function which thankfully Google Docs includes, albeit less robust to the MS Word variant.
The principle behind this is to find all the line breaks and replace them with nothing. This will remove all empty new lines, and therefore merge the lines of text into one block.
Removing Line Breaks in Google Docs using Regular Expression
Now, in Word this is very easy to do as all you have to do is find all the paragraph marks using ^p
in the affected lines and replace them with nothing.
With Google Docs, however, things are a bit more complicated: while it does support paragraph marks, you cannot use them in the Find and Replace dialog. Instead, you have to use regular expression.
The Regex equivalent for matching a line break is \n
. We can use this to match all new lines and merge the lines as follows:
- Go to Edit > Find and Replace, or just press Ctrl+H.
- In the Find and Replace box, enable the option Match using Regular Expressions.
- In the Find box, enter
\n
and leave the Replace box empty. All the new lines in the document will become highlighted. - Click the Replace All button to remove all the line breaks.
This will combine all the multiple lines in the entire document, irrespective of how they’re formatted. This includes any titles and headings which, ideally, we don’t want to merge with the preceding text.
Selective Replacement
In Word, this can be done simply by selecting the affected lines before using Find and Replace. Google Docs however ignores any selected content and instead searches the whole document.
Due to this limitation, we can use one of the following workarounds:
- Individually replace the line breaks by using the Next button to skip over specific line breaks as shown in the video tutorial.
- Copy the affected lines into a new blank document. Merge the lines from there, then paste the merged lines into the original document.
- Use a regular expression that only matches the affected lines.
The first two options are preferable, however they’re only practical when working with small documents. For large documents, using a suitable regex is a far more ideal solution to save time.
Here are some few expressions you can try:
\n
: Matches all line breaks\n\n
: Matches all double line breaks\n\n\n
: Matches three consecutive line breaks\r?\n(?!\r?\n)
: Matches only single line breaks. Titles and headings are usually followed by two or more line breaks, so this will skip them.