Bulk replace all instances of CO2 with CO<sub>2</sub>

Is it possible to bulk replace all instances of the carbon dioxide molecule notation CO2 with the proper notation (subscript 2)?

As of 2024, it’s “Find All”, and it’s a PITA that LO still isn’t able to search+replace all on its own.

It’s perfectly able - if you properly search for the 2 - using a regex like (?<=CO)2, which doesn’t select the CO, and uses them only as a condition (“assertion”) for the 2.

a screencast

Also, the suggestion of @LeroyG works just as well - not requiring to apply any direct formatting.

2 Likes

Thanks for the info + screencast. Using the regex + “₂” did the job, although I still think the dialog should make it possible to simply search for “CO2” and support sub/superscript in the Replace section since most users don’t know regexes.

image

Yes, you can.
Find “CO2”
Mark “Current selection only”
Find “2”
Click Find All
Apply sub/superscript.

2 Likes

Thanks. This two-step solution is easier for non-regex experts.

1 Like

Open the full Search&Replace tool (Ctrl H) and enable “Regular expressions” under “other options.” In “Find” write

(?<=CO)2

and click “select all:” all the “2” after a CO will be selected. Alt Tab to go to the document and now you can apply the formatting to all those “2” either as direct formatting (Ctrl Shift B) or by applying a character style.

1 Like

…and Replace all: with ₂.

1 Like