This is super handy for some problems:
>>> re.search('(?P<b>.b.).*(?P<i>.i.)', 'abcdefghijk').groupdict()
{'i': 'hij', 'b': 'abc'}
But what if I don't know what order to expect ahead of time?
[update]
Eg, say I have an input variable containing some unknown order of characters and it just so happens that 'b' comes after 'i'. I want to still be able to reference the groups for '.b.' and '.i.' without having to order my regex according to their order in the input var. So, I wish I could do something like this but I don't know if it's possible:
>>> re.search('(?P<b>.b.)|(?P<i>.i.)', unknown_order_alphabet_str).groupdict()
{'i': 'hij', 'b': 'abc'}
[end update]
I've searched around and racked my brain a bunch but can't generate any good leads. Guessing this functionality wouldn't exist because probably the only way for re to do this is to scan the entire string once for each group (which of course I could do in a loop instead) but I thought I'd see what the stackoverflow brain had to say about it.
Thanks for your help,
Josh