Find & Replace Regular Expressions

So I’ve been studying up on LibreOffice Regular Expressions.

I’ve got a file that uses Markdown (Twine to be specific). I am manually copying and pasting the text from it to LibreOffice.

Now that the Text is in LibreOffice, I want to format the text (using Regular Expressions) based on certain sets of Characters before and after them. So …

  1. All **Any Text Here**, I want the Text to be Bolded
  2. All _Any Text Here_, I want the Text to Italicized
  3. All <%Any Script Here%>, I want the Text to be in “Courier New” Font

I have figured out the proper Regular Expressions I need to put in Find for the 3 above examples I mentioned:

  1. \*\*.+\*\*
  2. _.+_
  3. <%.+%>

And I know how to use the Format button for the Replace field (for changing the Style and/r Font), but …

What can I put in the Replace field in order to keep the Text?

  • If I leave Replace empty, it just replaces each instance of the Regular Expression with no text.
  • If I put in the same regular expression in Replace as I put in Find, it just literally replaces each instance of the Regular Expression with the text of the Regular Expression. So if I put \*\*.+\*\* in Replace, all Regular Expressions of \*\*.+\*\* is now the literal text \*\*.+\*\*, but formatted with what I set in Format (and not the text it had before).

I hope my question makes sense.

And I know how to use the Format button for the Replace field (

The Format button in Find and Replace-dialog applies to Find and not to Replace.

Hello,

to reuse text you need to surround your Find expression by parenthesis: E.g. (\*\*.+\*\*) capturing the match into a buffer, which could be referred to by $1 (first pair of parenthesis), $2 (second pair of parenthesis) … and so on in the Replace field. E.g putting $1somemodification into the Replace will change all findings "found* into foundsomemodification.

If you want to change the format using Find and Replace you need to do the following (see also comment above):

  • Enter your Find expression (as per your questions)
  • Click button Find All (all findings in your complete text or your selection get selected)
  • Close the Find and Replace dialog (your finding are still selected)
  • Click the desired format button (e.g. B for bold) –or
  • Select a desired Character Style from the Styles sidebar (preferred way to do, since this avoids direct formatting)

Please note: This answer does not contain a check of your regular expressions mentioned in the question. This answer assumes, that the expressions given in your question find what you want to find.

Hope that helps.

You are converting from markdown-formatted documents to LibreOffice by finding and replacing the formatting marks and converting to LibreOffice formatting. The downside is that for each document you will have to go through each search and replace task individually OR create a macro to do the steps automatically. And, as you have seen, the process can be fidgety and unreliable.

You might find it faster and less error-prone to use a document conversion utility such as Pandoc. Using that utility you would convert the Markdown to OpenDocument XML directly. LibreOffice would then open the OpenDocument files with the formatting applied.

NOTE the conversion using Pandoc may not be flawless, but you should be able to convert and clean up much more quickly than any Find and Replace techniques in LibreOffice.