I'm having trouble writing a function that will take a chemical formula string such as "NiNFe(AsO2)2" and remove one of the elements.
my current attempt is:
pattern = new RegExp(symbol, "g")
formula.replace(pattern, "")
If the symbol is "N" and the formula is "NiNFe(AsO2)2" I end up with "iFe(AsO2)2" instead of the desired "NiFe(AsO2)2". Does anyone know how to code this in such a way that it would distinguish the N from the Ni and replace just that?