Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Python

r"
(?:[\(\)eA-Z][a-z]*(?:_\{? ?\d*\}?(?:(?:_\d)?)*)?)+(?:\^\{? ?\d*[\+-]?\}?)?
"
g

Description

Matches chemical formula written with latex, ex: H_2O, C_5H_12, Pb(NO_3)_2

Submitted by Jingjie Yang - 8 years ago