RegEx for parsing chemical formulas

后端 未结 4 1501
生来不讨喜
生来不讨喜 2020-12-03 16:05

I need a way to separate a chemical formula into its components. The result should look like this:

   Ag3PO4 -> [         


        
4条回答
  •  离开以前
    2020-12-03 16:36

    This should just about work:

    /(\(?)([A-Z])([a-z]*)([0-9]*)(\))?([0-9]*)/g
    

    Play around with it here: http://refiddle.com/

提交回复
热议问题