Ask Your Question

Can LibreOffice search–&–replace 'hard returns' with 'space' chars?

asked 2016-12-17 21:09:32 +0200

mkraft gravatar image

A common problem with 'plain text' that's copied-&-pasted from the Internet into a document is that 'hard returns' are retained.

Without some kind of automated 'replace' operation, the hard returns at the ends of (often truncated) lines of text then have to be removed manually.

Can LibreOffice automate this?


edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted

answered 2016-12-19 03:47:50 +0200

paul1149 gravatar image

If I understand what you're looking for, I think you can do it inherently in LO's F&R function. Select text that includes the paragraph ends you want to replace. Then go to F&R. Under "other options" check "this selection only" and "regular expressions". Now put $ in the Find box and a space in the Replace box, and hit Replace All.

edit flag offensive delete link more

answered 2016-12-17 21:36:31 +0200

floris v gravatar image

updated 2016-12-18 09:00:58 +0200

You can do that easily with the alt search extension.

\p is for paragraph breaks.

edit flag offensive delete link more


I saw the extension before I posted but didn't find that particular operation in the displayed list of operations.

Can you reply with the actual steps/keystrokes to use to replace 'hard returns' with 'space' characters (i.e., once that extension is installed)?


mkraft gravatar imagemkraft ( 2016-12-17 22:58:50 +0200 )edit

In the Search for: box select the Regular drop-down.

Find Paragraph (ending mark) /p - select that.

That will enter /p in the Search for box.

In the Replace box enter the space.

Then do your find and replace.

LibreTraining gravatar imageLibreTraining ( 2016-12-18 01:21:07 +0200 )edit

Thanks. Just to be clear, that's using thisextension –– –– ?

And there's no way to do it in LO itself (i.e., w-o the extension)?

mkraft gravatar imagemkraft ( 2016-12-18 12:45:19 +0200 )edit

The buil-in 'F&R' cannot span paragraphs. within a 'Find: ' expression.
AltSearch also has to handle complications and is not very efficient when spanning paragraphs. I tried with about 340 paragraphs of a total of about 250000 characters and it took about a minute to make one single paragraph of it.
However, it worked!

Lupp gravatar imageLupp ( 2016-12-18 16:02:18 +0200 )edit

answered 2016-12-18 15:32:58 +0200

gabix gravatar image

updated 2016-12-22 10:48:42 +0200

OOoFBTools has a feature of automatic or manual joining of broken paragraphs.

However, for this particular case, LO's own find and replace routine is enough. Just put \n in the Search For field, a space (or whatever you want) into the Replace With field and enable regular expressions (expand More Options to see it).

edit flag offensive delete link more


Thanks for those replies. Just to be clear, though, there is one particular F&R operation I'm trying to do, and most often it concerns only single paragraphs.

E.g., text copied from documents often appears as:

"something intimate and fundamental about the Germans which Tacitus never understood and which all our historians miss — they are of necessity his- trionic. Note I do not say it is a vice of theirs."

Just looking to reformat such text to run normal line length.

mkraft gravatar imagemkraft ( 2016-12-18 17:46:46 +0200 )edit

Unfortunately, the formatting of the above comment, as I composed it, wasn't preserved. The italicized text was actually four short lines of text, not the two 'normal' length lines as shown above.

I want to just be able to select such paragraphs and find-&-replace the 'hard returns' at the end of each line with a 'space' character (i.e., within individual paragraphs -- being able to do it globally within a document would be optimal but I don't normally need that).

mkraft gravatar imagemkraft ( 2016-12-18 17:51:20 +0200 )edit

That is exactly what the above extension can do: join broken paragraphs. In the manual mode, 5 options are available:

  • remove paragraph breaks;
  • replace paragraph breaks with a space;
  • remove line breaks;
  • replace line breaks with a space;
  • remove line breaks and paragraph breaks.

In the auto mode, also several options are available, in particular, to join lines with sentences split by paragraph breaks on lowercase letters, numbers, punctuation marks, quotation marks and brackets.

gabix gravatar imagegabix ( 2016-12-19 10:20:00 +0200 )edit

Thanks. Can you explain how "line breaks" are distinguished from "paragraph breaks"?

Is the latter just a series of two or more 'line breaks'?

Also, if all one wants to do is replace a 'line break' with a 'space' can that be done natively within LO (a previous replier suggested it could) or does that require the extension?

mkraft gravatar imagemkraft ( 2016-12-21 05:00:30 +0200 )edit

Line breaks are another type of breaks, ones that you enter with Shift+Enter. They appear as kind of small arrows at the line end. One paragraph can contain many line breaks and it still is one paragraph, that is the difference. If what you refer to as 'hard returns' are really line breaks and not paragraph breaks, then yes, you can use the internal find and replace routine by specifying \n in the Search field, space in the Replace field and turning regular expressions on.

gabix gravatar imagegabix ( 2016-12-21 08:30:06 +0200 )edit

Thanks. My inquiry concerned primarily imported text that's been copied-&-pasted from webpages. I'm guessing the end-of-line characters (which aren't visible) are what you refer to as 'paragraph breaks.' An example of what I'm referring to can be found at: If you scroll down a little (or search for "PRAISE OF THIS BOOK" to quickly relocate), you will see the kinds of paragraphs I'm referring to. Are these EOLs paragraph breaks?

mkraft gravatar imagemkraft ( 2016-12-21 17:21:42 +0200 )edit

Ah, then it is clear. No, they aren't paragraph breaks (at least when I open the file with LO Writer) but line breaks. And yes, in this case they can replaced by LO's own routine (I have amended my answer).

gabix gravatar imagegabix ( 2016-12-22 10:46:20 +0200 )edit

Got it, thanks.

mkraft gravatar imagemkraft ( 2016-12-23 04:36:52 +0200 )edit

answered 2019-11-06 17:38:04 +0200

mrodent gravatar image

These answers don't appear to be correct as at 2019-11-06 (LO Writer 5.1):

Find & replace: ensure "regex" is checked.

  • "\n" then finds SOFT line breaks
  • "$" finds HARD line breaks (= paragraph marks)
edit flag offensive delete link more


So how your answer differs from @paul1149's answer that suggests using $ regex for "hard breaks", which is consistent with information from help? Did you also test AltSearch (to prove answer @floris v gave is incorrect), and OOoFbTools (for answer by @gabix, which also mentions \n for soft breaks - see the comments under that answer to see how the original question turned out to not want hard breaks, but soft breaks)?

Mike Kaganski gravatar imageMike Kaganski ( 2019-11-06 17:43:01 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-12-17 21:09:32 +0200

Seen: 3,041 times

Last updated: Nov 06 '19