Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2026-06-30 06:42
Flavor·PCRE2 (PHP)

/
((?![^<>]*>)(?:(?:(?:(?:(?:H[eogf]?|L[iau]|B[eari]?|C[arouseld]?|N[eiapdb]?|O[sg]?|F[rle]?|M[gon]|A[lrsgutc]|S[icernmb]?|P[uabotmrd]?|Kr?|T[icebmalh]|V|Z[nr]|G[ade]|R[buhena]|Yb?|I[nr]?|Xe|E[ur]|Dy|W|U)|[()\[\]])+(?:(?:<su[bp]>[1-9][0-9]*<\/su[bp]>|[1-9][0-9]*))*)){2,}|(?:(?:H[eogf]?|L[iau]|B[eari]?|C[arouseld]?|N[eiapdb]?|O[sg]?|F[rle]?|M[gon]|A[lrsgutc]|S[icernmb]?|P[uabotmrd]?|Kr?|T[icebmalh]|V|Z[nr]|G[ade]|R[buhena]|Yb?|I[nr]?|Xe|E[ur]|Dy|W|U)|[()\[\]])+<su[bp]>[1-9][0-9]*<\/su[bp]>)(?:[+-](?![A-Za-z0-9]))?(?:(?:\s*[·•*]\s*|\.(?=[A-Za-z(\[]))(?:(?:<su[bp]>[1-9][0-9]*<\/su[bp]>|[1-9][0-9]*(?:\/[1-9][0-9]*)?|[xn]))?(?:(?:(?:H[eogf]?|L[iau]|B[eari]?|C[arouseld]?|N[eiapdb]?|O[sg]?|F[rle]?|M[gon]|A[lrsgutc]|S[icernmb]?|P[uabotmrd]?|Kr?|T[icebmalh]|V|Z[nr]|G[ade]|R[buhena]|Yb?|I[nr]?|Xe|E[ur]|Dy|W|U)|[()\[\]])+(?:(?:<su[bp]>[1-9][0-9]*<\/su[bp]>|[1-9][0-9]*))*)+(?:[+-](?![A-Za-z0-9]))?)*)
/
gm
Open regex in editor

Description

Matches for a chemical structure in a form similar to CHBF<sub>5</sub>-.K+. Accounts for every scenario I could think of (hydrates, adducts, ionic bonds, positive/negative charge indicators, etc)

Submitted by Justin Hyland