ChemPal Documentation - v1.6.0
    Preparing search index...

    Module helpers/formulaPattern

    Functions - Science Helpers

    buildFormulaPattern

    Builds the chemical-formula matching regex, parameterized by the subscript token for the source format. Everything else is shared: element gating, an optional ionic charge, salt/hydrate separators with optional coefficients, and a "head" that must look like a formula — either ≥2 element/bracket units, or a single element carrying a real subscript.

    scoreFormula

    Scores how "formula-like" a candidate is, so the best of several matches can be chosen. Favors more element symbols first (a real formula packs several), then the presence of a subscript/count, then raw length — so NaOSOCH3 outranks a two-letter coincidence such as IN (from "EINECS") or CS pulled out of surrounding codes/prose.

    pickBestFormula

    Returns the most-likely-correct formula from a list of raw matches (highest scoreFormula, first match winning ties), or undefined when the list is empty.

    Regex Patterns - Science Helpers

    FORMULA_ELEMENT_PATTERN

    Element-symbol alternation (all 118 symbols, folded into per-first-letter character classes). Gates formula matching so ordinary prose isn't read as a formula.