Can i set some parts of the text so that only these parts will take a certain style?

hi, i have a big file containing thousands of questions, references and answers;

since most of the text is not formatted yet i need to format the Answers with a certain style (Questions and References will have their style too)
the problem is that many answers may be more long than others and instead of containing manual line breaks contain several paragraphs (so if i assign a style with a command they won’t be formatted completely but only up to the first paragraph).

but all answers start with an "R: " and end up with two end paragraphs (i mean the last paragraph of the complete answer and a next empty paragraph).

not finding any other way i’m using the alternative find and replace in two steps:
1st i search all paragraphs starting with ^ R:. * $ and replace them with \0\P{_answ} to assign the style
but as said this leaves the many longer answers incomplete (formatted only up to the first paragraph)
2nd i manually select each incomplete answer and replace all the \p paragraphs with \n manual line breaks in order to fix the style to to the complete answer
but it’s all manual, file id hudge and i’m not ending up anymore (and can’t believe there’s no way to automate the process with less manual work)

so don’t know if terms or ideas are correct but i’d like to understand if ther’s a way to define somthing like a sort of blocks using the first part "R: " as the initial distinctive part of some text and the last paragraph of the anwer as the end (or maybe the distinctive following empty one - and i’m not sure but i intended that could be not possible) as the final part of the block in order to assign to the answer it’s style, is there a way to do it? if not this way any other solution?
(i thought also that if i could find a way to replace the two adjacent Answer paragraphs in one ending keyword (as the final part of the block of the Answer) this unique ending Anwer paragraph would be distinguished from the Questions and Reference end paragraphs in order to replace all the contained previous Answer paragraphs in line breaks so that the above mentioned step 1) will do the work - but i cant’ find a way to search the two last paragraphs of the Answer and don’t know if the approach is correct too) any ideas?

@floris_v thanks for your answer

@ajlittoz thank you for your long detailed suggestions/answer

If all Questions and Answers appear at the beginning of the document and the references at the end, first put the references in their own document. Then find something that occurs in all questions, if they start with Q:, that’s great. If there’s something else, use that. *If you want to apply a paragraph style to a set of paragraphs, all you have to do is select a part of each paragraph, you don’t have to select the entire paragraph, because a paragraph style affects the entire paragraph, not only the selected text (it’s different for character styles and page styles, of course).

If all you have is paragraphs with questions and paragraphs with answers, then obviously everything that isn’t a question is an answer. So if all text was formatted as Default paragraph style, fine. First mark all questions by whatever you found that they have in common, then format them as Question (new style). Then use the Find @ Replace to replace the Default style by the Answer (new style) style and you are sone.

To format the paragraphs starting with R:, you only have to find ^R:. Then tick Find all, close the dialog box and apply the correct paragraph style.

To show the community that your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers.

There are several flaws in your method.

A paragraph must be terminated by a paragraph break Enter. Using a line break Shift+Enter only causes line wrap without leaving the paragraph. This means that vertical spacing between paragraphs is not honoured and you get a simple line spacing instead.

NEVER use an empty paragraph to vertically space two blocks of text. This will play nasty tricks on your back one day or another when Writer makes decisions about text flow. Inter-paragraph spacing is tuned in Indents & Spacing tab of any paragraph style, Spacing section where you can differentiate spacing above and below.

The paragraphs making an answer must be assigned the same paragraph style, whether they are first or not because semantically they equally contribute to the answer. You can optionally prefix the first paragraph of an answer wit R: if the typographical attributes do not make clear this is the beginning of an answer (usually answers can be more indented than question and use a different variant like italics vs. Roman in the question or regular vs. bold).

With an R: prefix, I suggest you indent your answer style ~1cm Before text and you set First line to the negative of this value (-1cm) to create a hanging indent.

On the first answer paragraph you type “R:” Tab, while on subsequent paragraphs you only type Tab to align on the indent.

Alternatively, you can create two paragraph styles, say Answer and Answer1 (for first paragraph). Start by creating Answer. Define its Before text indent and let First line at 0cm.

When done, right-click on Answer name and New to create Answer1. Change only First line to set it negative of Before text and nothing else in any other tab. Observing this last remark, any modification you’ll make on Answer (font face, size, spacing, …) will automatically be forwarded to Answer1 and the styles will remain in sync. In the Organizer tab, set Next Style to Answer. This will cause an automatic paragraph style switch to Answer when you hit the Enter key in an Answer1 paragraph.

How to use that?

When you start an “answer”, switch to Answer1 style. Type “R:” Tab and the answer. At end of paragraph, hit Enter. You’re now positioned at start of an Answer paragraph without the need to type Tab to go to the indent.

How to incorporate it to existing text?

Unfortunately, there is no automatic procedure. Click in an answer paragraph and give it the correct paragraph style: Answer1 for first, Answer for the others. I understand your answers are already styles, so you need to do it only on the first paragraphs and eventually adjust the prefixes.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.

hi, don’t know if may be useful but in case i share because i save a lot of time when i end a book and add in my resume book hundreds of related questions, references and answers (each with it’s own style) and now only with a click (maybe my eng translation is not exact :))
/alt search/batch/edit ($HOME/.config/libreoffice/4/user/config/AltSearchScript.txt)
with the following:

[Name] New book format fixing (markers adding and style format fixing for questions, Refs and Answers)
[Parameters]   MsgOff  Regular  NoSummary

; 1a) Separate blocks

[Find]\n\n
[Replace] _endA_\p\p
[Command] ReplaceAll

; 2a) format questions, add endQuestion & startRef marker:

[Find][\b\?]\n([:upper:][:lower:][:digit:])
[Replace] ?_endQ_\P{_q123}\p\P{_Ref}_startRef_\1
[Command] ReplaceAll

; 2b) add endRef & startA marker, _Ref style mantaining & add _Answ style

[Find]\nA:
[Replace] _endRef_\P{_Ref}\p\P{_Answ}_startA_A:\t
[Command] ReplaceAll

; 3a) refinements - clear spaces after tabs

[Find]\t 
[Replace]\t
[Command] ReplaceAll

; 3b) clear gray stuff before spaces

[Find]\s 
[Replace] 
[Command] ReplaceAll

; 3c) clear spaces before question marks

[Find] \?
[Replace]?
[Command] ReplaceAll

; (save and click update button before execute)

(formatting fixed to make the answer readable)