Regular expression for extracting chemical formulas and symbols

Is it possible to recognize or extract only the chemical formula and symbols in the text, for example:

    text text h2o, text text Ho3NiGe2, 20% 15°C text text text text

PS: the output will be: h20, Ho3NiGe2,

-1
source share
1 answer

Do you want to:

Regex: \b([A-Z][a-z]{0,2}\d{0,3})+

Demo

0
source

Source: https://habr.com/ru/post/1685613/


All Articles