I\'m trying to write a method for an app that takes a chemical formula like \"CH3COOH\" and returns some sort of collection full of their symbols.
CH3COOH would retu
The solution with regular expressions is the best approach if you need to handle only simple cases. Otherwise you need to build something like Abstract Syntax Tree and evaluate it or use Polish Notation.
For example, TNT formula C6H2(NO2)3CH3 should be presented like:
(+ (* C 6) (* H 2) (* (+ N (* O 2)) 3) C (+ H 3))