fork download
  1. import re
  2. myText = 'sgasgAAAaoasgosaegnsBBBausgisego'
  3. myRegex = re.compile('(?P<long>(?P<short>AAA)(?:.*BBB)?)')
  4. x = myRegex.search(myText).groupdict()
  5. print(x)
Success #stdin #stdout 0.01s 7172KB
stdin
Standard input is empty
stdout
{'short': 'AAA', 'long': 'AAAaoasgosaegnsBBB'}