Google Docs is handy to use especially for collaborations, but its inability to find and replace extra carriage returns or newlines is a pain. Here’s a workaround.
Some organizations I work with use Google Docs. I love how easy it is to use and to collaborate with others. However, one thing that I constantly need to do and couldn’t in Docs was to get rid of extra carriage returns or newlines using find & replace.
Thankfully, a member of an editors’ forum was able to show me how to do it. I’m jotting it down here as I’m sure others face the same problem!
The writer used two carriage returns or newlines;1 I’d like to change that to one carriage return/newline.
1. In your Doc, open Find & Replace
2. Tick the “Match using regular expressions“
3. In the “Find” box, type the following:
4. Leave the “Replace with” box blank and hit either “Replace” or “Replace all.”
And voila! The double newlines are now single.
Often, I have to copy & paste the text to a website/blog interface, so not having to manually delete the extra newlines saves me a lot of time. (To improve readability in Docs in the meantime, I usually change the paragraph line spacing.)
I don’t understand the code so I’m afraid I can’t explain what the code actually means, but I’m grateful to my colleague for teaching me this!
In case you’re wondering, this is a lot easier to do in Word.
1. Open “Replace“
2. In the “Find” and “Replace” boxes, put the following (the parts in bold):
"Find what" box: ^p^p "Replace with" box: ^p
The “p” should be lowercase; I’ve tried it with an uppercase “P” before and it didn’t work.
Note that in Word, you can have either paragraph breaks or line breaks (if you turn on hidden characters, the paragraph breaks appear as the backwards P and the line break as a little bent arrow).
If your document has line breaks (which it may if you’ve copied text from a web page, for example), then instead of ^p, use lowercase l (letter L):
"Find what" box: ^l^l "Replace with" box: ^l
(Or you can replace them with a paragraph break, in which case, in the “Replace with” box, you’d type ^p. In Word, I personally find it easier to work with paragraph breaks.)
Hope that helps!
Need help with your scholarly writing project? Let’s discuss! Please contact me with your requirements via the contact form or email me at firstname.lastname@example.org.
- As a non-techie, I understand only that both are ways to code a move to the next line. Here’s a Wikipedia article on carriage returns (it links also to the newline article) and another slightly more technical explanation
Pure awesomeness! Thank you.
Glad you found it useful! I was amazed it was this complicated ^^
That “?=” in “(?=\n)” is called “before text matching” and if you click the “Help” link to the right of the checkbox option “Match using regular expressions” you’ll get to a Google Docs help page and on that there’s a link to the RE2 Github page. On that page search for “?=” for that rather short description of the RegEx. Weirdly it mentions that this is “NOT SUPPORTED” and yet it works?
To explain it more, and someone else may be able to further clarify, this will look for the text inside the “(?=..)”, in this case the newline, but not include it in the actual match and so that text doesn’t get touched by the replace.
There’s plenty more options in that RE2 spec to give the average user nightmares 😜
Thank you, @ConceptRat! Every time I’ve attempted to look at the RE2 options, I’ve end up feeling dizzy 😂 so I’m glad that you explained this bit for us.
I knew how to do this in Word, but GDocs were driving me crazy not being able to do this. This is gold, thank you.
Hi Martin, yup, it drove me crazy too. Was so grateful when someone shared this tip.
To add to what ConceptRat wrote, that bit of RE2 says “match a newline when and only then it’s before another newline,” and when you leave the ‘Replace’ box blank you’re saying “delete the match you find,” which in this case is *just* the first newline.
Thanks so much for discovering this; great little workaround for Google’s unconscionable lack of support for RE’s in the replace field.
thank you thank you thank you
thank you so much!
Thank you for this. On trying this I discovered something. Sharing it here. Follow step 1 and 2. In find box type \n In the replace box type enter(blank space) and replace all line breaks at once. No add on needed
Thanks, Mona, for sharing this! I’ll give it a try.
I’d like to “control + H” find and replace “;”, or “,” within the text with a new line or new paragraph. This would be a good way to take something like a densely packed laundry list that was written narrative form and make it into stack of individual items, clearer.
I don’t see from what you have said here how to do that.
Hmm, I know how to do that in Word but not Docs. Docs could definitely use a more robust find & replace!
In case anyone is wondering how to do that in Word:
In the “Find what” box, type whatever punctuation mark you want to replace
In the “Replace with” box, put either ^p (new para) or ^l (new line).
It seems for more complicated edits, professional editors suggest the workaround of saving the Doc as a Word doc, making your changes there, and then putting it back into Docs.
Thank you, I was searching for ages for this. Do you know how to do the opposite (ie add an extra line break)? I’d assumed replacing \n with \n\n but this just inserts the characters “\n” into the text.
Hi Martin, I wish I knew too. Sorry can’t help…
Brilliant, thank you!
You are a magician because this is magic! Thank you for this trick! So the trick is it uses \n rather than ^p. Now I feel like a magician. Except you don’t need to be a magician or illusionist to pull off this amazing magic trick. =)
I often want to do the opposite – ie, change ^p to ^p^p. Couldn’t immediately see a way to do that in Docs – but if I just paste the whole thing into Word and back that’s pretty quick. 🙂
Yup, I agree. It’s easiest to just pop it into Word!
is there a way to do this in google sheets?
Hi Nate, sorry, I wish I knew too! Hope you can find the solution.
THANK YOU! I’ve been trying to find out how to do this for weeks!
Just here to say THANKS!!
I had a similar (but opposite?) problem. I had text where the word-wrapping within paragraphs was performed manually by newlines, and then there were 2 newlines at the ends of paragraphs. I needed to delete the newlines in the middles of the paragraphs, but not the newlines that separated actual paragraphs. Thanks to this article, I managed to figure out this little gem in the replace box, which replaces newlines which are not followed by newlines:
First – thank you! I’m relieved that I always open the first three google answers that seem helpful, then read.
Second – you’re the only one of three that recommended a solution and NOT an extension/plug-in! Yaay!
Third – one of the extension recommendations came from a google forum, so you CRUISE above the others.
Fourth – THANK YOU for sharing your discoveries and solutions AND for still being online and available after so much time. I’m a huge fan of random yet helpful information.