In find/replace, when the "regular expressions" options box is checked, the product intentionally has "\n" mean one thing in the search box, and a different thing in the replace box:
From the help file:
\n in the Search for text box stands for a line break that was inserted with the Shift+Enter key combination.
\n in the Replace with text box stands for a paragraph break that can be entered with the Enter or Return key.
This means that I can never search for a paragraph break, and I can never replace anything with a line break.
As these are two different characters, they should really be represented by different expressions in the find/replace feature so that users have the flexibility to find on either one, and replace with either one.
I can understand your problem, but for me it is only a theoretical problem. I can't think of a situation, where I want to search for a paragraph break or want to replace something with a line break. Can you give one or two examples?
2 have occurred just in my household:
1- my daughter wanted to cut and paste song lyrics into a story she was writing, but in paragraph form. So she needed to at the end of every line hand delete the paragraph break and replace it with a space. It was a very long song.
2- I have hundreds/thousands of old emails from back when they were sent only in plain text format. When you would reply, the paragraphs would be word-wrapped at 76 characters (or so) and on each new line a "> " would be prepended. We'd format new paragraphs by having 2 carriage returns. Preserving old emails into a document requires replacing all those single carriage returns with spaces and the double carriage returns with single carriage returns. A lot of reformatting.
Basically - this is something you run into with reformatting text obtained from elsewhere. Also, it would be helpful for bringing text from or to a spreadsheet format.
Clearly it is not a theoretical problem. In fact, a quick google search finds complaints about this going back 5-6 years, with some painful workarounds. But really this should just be in the already available find/replace feature. Noone should have to cut and paste thier LibreWriter doc into MSWord to be able to replace on <CR>.
Thank you for the explanations and examples. I agree, that there are some situations, where it might be useful. Set to NEW.
For sure there are such situations in which one would like to search for a paragraph mark and replace it with something else, and I am speaking as a Technical Writer often having to do this.
The problem is that there is a misunderstanding as to what a Shift+Enter does. Shift+Enter inserts a page break and not a line break as the pseudo-help states.
MS Word also has a "Special" button in the Search & Replace window to easily pick regular expressions.
Please correct this issue and make \n or \p to represent a paragraph mark.
Use case: I want to search for certain lines containing certain text and replace that text together with the line on which that text was placed. I can't make any such replacement as \nTextToReplace is not found.
(In reply to Daniel Grigoras from comment #4)
> The problem is that there is a misunderstanding as to what a Shift+Enter
> does. Shift+Enter inserts a page break and not a line break as the
> pseudo-help states.
No, it does not. Shift+Enter inserts a "line break", searchable as "\n" or as "\u000a"
> MS Word also has a "Special" button in the Search & Replace window to easily
> pick regular expressions.
And? Otherwise, we have our own regex syntax drawn from perl as implemented by ICU.
> Please correct this issue and make \n or \p to represent a paragraph mark.
Not going to happen, the ICU library String search and its regex implementation meets our needs of manipulating paragraphs.
"$" already is unique representation of the end of a Paragraph object. It has no meaning in a replacment string--just a search string where it is either the end of a paragraph object, or for composing a regex match at end of paragraph.
> Use case: I want to search for certain lines containing certain text and
> replace that text together with the line on which that text was placed. I
> can't make any such replacement as \nTextToReplace is not found.
Post an example we'll figure it out for you.
Created attachment 139959 [details]
findReplace.odt: sample document showing two situations LO can't handle
I think this document demonstrates the two situations described in comment 2 and also covers the "\nTextToReplace" concept from comment 4 which in MSWord search syntax would be "^pTextToReplace".
The key idea here is to do these things as single searches (preferably via a replace all). Otherwise the user has to make multiple "replace/next" passes through the document to accomplish each task.
*** Bug 91033 has been marked as a duplicate of this bug. ***
*** Bug 112575 has been marked as a duplicate of this bug. ***