ChemPare Documentation - v0.0.0
    Preparing search index...

    Function findFormulaInHtml

    • Match for a chemical formula (with or without subscript tags) in a string of html. It does not currently work for formulas with parenthesis or brackets.

      The function searches for valid chemical element symbols followed by optional subscript numbers. It requires at least two element-number combinations to consider it a valid formula.

      Parameters

      • html: string

        The HTML string to search for a formula

      Returns undefined | string

      The HTML that shows the chemical formula only, with proper subscript formatting, or undefined if no formula found

      findFormulaInHtml('foobar K<sub>2</sub>Cr<sub>2</sub>O<sub>7</sub> baz')
      // Returns "K₂Cr₂O₇"

      findFormulaInHtml('H<sub>2</sub>SO<sub>4</sub>')
      // Returns "H₂SO₄"

      findFormulaInHtml('Just some text')
      // Returns undefined

      https://regex101.com/r/H6DXwK/6 - Regex pattern explanation