Ruby regex for chemical formulat subscript/superscript : I want to substitute sub and sup tags into a chemical formula, for example C7[2H]5NaO2, and get as as result:

    C<sub>7</sub>[<sup>2</sup>H]<sub>5</sub>NaO<sub>2</sub>

The numbers inside the tags can be two digit numbers. I know so far that /(\d+) / will match all digits, and /\[(\d+)/ matches the digit after the [, but I don't know how to combine these two. Thanks in advance.