Sublime Forum

Wrapping all numbers in <sub>..</sub>

#1

Hi everyone,

does anyone know a quick solution how to wrap the numbers of raw chemical formulas (e.g. C10H12N2O5S) into <sub>..</sub> tags (e.g. C<sub>10</sub>H<sub>12</sub>N<sub>2</sub>O<sub>5</sub>S) with SublimeText? Wikipedia renders it subsequently as C10H12N2O5S.

This is not a true feature request. If you demand so, I will move my question to StackOverflow.

Cheers,
Peter

0 Likes

#2

E.g. you can press ctrl+h to open the replace window and press alt+r to enable regex. Then search for \d+ and replace it with <sub>$0</sub> and press “replace” multiple times or “replace all” if you haven’t other numbers in the document.

5 Likes

#3

Working nicely. Thanks!

0 Likes

#4

If you find yourself doing this very frequently, you could easily write a command that does it for you, either by manual invocation or by replacing as you type.

0 Likes

#5

Here’s another approach.

Open ‘find’ and make sure regex is enabled. Use \d+ as the find string and choose ‘Find All’

Then press Alt+Shift+W (Ctrl+Shift+W on mac) and type ‘sub’ (or any other tag). That’s it!

:slightly_smiling:

0 Likes