Find-replace any characters within brackets and change format

I have a .docx document within which are scattered sentences or phrases which are enclosed in square brackets.
I want to change the formatting of the characters which are enclosed in square brackets to italic.
How can I do that?

I do not want to italicize the brackets themselves.

Thank you.

  • SEARCH&REPLACE
  • regular expressions
  • SEARCH \[.+\]
  • Find all ↦ each of the found text fragments is highlighted
  • leave SEARCH&REPLACE
  • the text fragments are still highlighted
  • apply Emphasis character style (avoid direct formatting)

Always work on (native) .odt documents. Word format may cause unpleasant results.

EDIT
The square brackets will also be italic. If you do not wish this, add this in your question.

1 Like

Thank you. It is kind of you to help me.
I have changed the question to state that I do not want to italicize the square brackets themselves.

Make a second step:

  • SEARCH&REPLACE
  • regular expressions
  • SEARCH \[|\]
  • Find all ↦ each of the found text fragments is highlighted
  • leave SEARCH&REPLACE
  • the text fragments are still highlighted
  • apply No Character Style or any other character style (avoid direct formatting).
    (To erase direct formatting hit shortcut CTRL + M)
1 Like

Your assistance is wonderful.
I have not found a character style named Emphasis.

(post deleted by author)

This will indeed italicise the sequence and IS the way to do it with .odt documents. Unfortunately OP mentions .docx. The character style application will be lost at save time and replaced with direct formatting.

I highly recommend @Catlike to save own documents as .odt instead to benefit the superior formatting possibilities offered by Writer. If documents are “external”, no luck and expect more and more damage with successive edits.

Open the Styles window; make sure that you have selected character styles - top, second icon from left looking like letter A; use the drop-down list at the bottom of the window to select All Styles.

1 Like

Excellent! Thank you kindly. This is a side of LibreOffice Writer I had not known, and I’ve used Writer for over a decade!
I suppose there is always more to learn about it.

If you need to do this with docx the find&replace dialogue can directly change the formatting of the replaced text. Use the button you can reach when opening “further options” to set italics.
Use carefully: The same button sets format for searching.
.
One additional hint: I in a similiar case
\[.*?\] for the search. This avoids problems for multiple brackets in a paragraph like aaa [bb] ccc [dd] eee
Usually search is greedy and would put everything from [b to d] in italics.

3 Likes