i'm having trouble evaluating a string with a regex pattern.
Essentially, I have a bunch of strings, eg.:
ph2h_sup_at_cp p_sup_50g_v ph2h_sup_3d_p
They have specific groups:
- ph2h_sup or p_sup
- at or {x}g or {x}d (e.g. 50g/50d/at)
- either p/v/cp
My pattern is:
pattern = r'(ph2h_sup|p_sup)_((([0-9]+)(d|g))|at)_([c]|[p]|[v]|[cp])'
string = "ph2h_sup_60g_cp"
matches = re.findall(pattern, string)
The result is:
[('ph2h_sup', '60g', '60g', '60', 'g', 'c')]
What I need is:
[('ph2h_sup', '60', 'g', 'cp')]
What am I doing wrong with my pattern?