I want to catch these patterns
GH_AP_FB
RB_GO_PY_YL_MI
GB
The general regex rule is ([A-Z]{2})(_[A-Z]{2})*
How can I implement this in Python and also have access to each [A-Z]{2} element ?
Also, what about patterns with more depth (nested groups), ex:
GH_AP_FB-RB_GO_PY_YL_MI-GB
GH_AP-RB_GO_MI-GB_TT-HG-RT-KK_LL_MM
FB
--> [ [GH, AP, FB], [RB, GO, PY, YL, MI], [GB] ]
--> [ [GH, AP], [RB, GO, MI], [GB, TT], [RT], [KK, LL, MM] ]
--> [ [FB] ]
Is there a better way from using regex, like parser with easy to implement rules ?
[EDIT]
Please, no answers using str.split(), because the separators "_" and "-" may also be used before or after this patterns in a wider string.