Skip to main content
Participant
May 11, 2023
Answered

Replace "CO2" by a "2" in subscript

  • May 11, 2023
  • 1 reply
  • 3285 views

Hi everyone !
I have an InDesign document with more than 400 times "CO2". 
I absolutely need to replace all "CO2" by CO2 : the "2" has to be in subscript.
Is there a way to use the tool "Replace" with subscript ? 
Thanks

Correct answer Frans v.d. Geest

Use GREP!

Create a subscript character style, then create a Paragraph style that had that character style to be used with this GREP:

(?<=CO)2

 

Do you have NO2 and H2O as well? You can catch them all in one GREP:

([CN]O)\K2|(H)\K2(?=O)

1 reply

Frans v.d. Geest
Community Expert
Frans v.d. GeestCommunity ExpertCorrect answer
Community Expert
May 11, 2023

Use GREP!

Create a subscript character style, then create a Paragraph style that had that character style to be used with this GREP:

(?<=CO)2

 

Do you have NO2 and H2O as well? You can catch them all in one GREP:

([CN]O)\K2|(H)\K2(?=O)

Participating Frequently
August 22, 2024

I added ([cn]o)\K2|(h)\K2(?=o) to also apply this to all lowercase instances (co2, no2, h2o) too, but how do I capitalize the letters? Can I alter this GREP, do I make a new GREP?

Participating Frequently
August 22, 2024

In case anione else wonders, this is how I wound up doing it: I merged Frans' uppercase GREP and my lowercase GREP together into:

((?i)[CN](?i)O)\K2|((?i)H)\K2(?=(?i)O)

 

and I added a new GREP to capitalize all lowercase instances:

(?i)[cn]o(?=2)|(?i)h(?=2)|(?<=2)o

 

There might be a more effcient GREP string, but this seems to be working