This would best be explained with examples.
Here is a line before I do anything:
Monohydrogen_Phosphate HPO%4^2-
Here is what I’ve done so far: Monohydrogen Phosphate | HPO%4^2-
Here is what it should be when finished: Monohydrogen Phosphate | HPO42-
The % will put the first number (if any) and + or – signs (if any) in a <sub> tag, and the ^ will put the first number and +/- in a <sup> tag.
I am using Javascript’s RegEx replace, but I don’t mind switching to PHP.
I would use
Here’s an example:
which will output:
EDIT:
I was thinking about compound(?) elements such as Li2CO3 so I came up with a longer but better solution.