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

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?

Thanks.

You can do that easily with the alt search extension.

\p is for paragraph breaks.

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)?

Thanks.

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.

Thanks. Just to be clear, that’s using this extension –– https://extensions.libreoffice.org/extensions/alternative-dialog-find-replace-for-writer –– ?

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

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!

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).

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 archive.org 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.

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).

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.

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?

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.

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: Full text of "The Path To Rome". 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?

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).

Got it, thanks.

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.

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)

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 @anon87010807 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)?