I have several substrings which I want to search for, let's say: substrings = ['ABC', 'ABCDE']. I also have several strings like 'xyzABCxyz', 'xyzABCDExyz'. My regex pattern provided to re.search() is: '(%s)' % '|'.join(substrings). Now, searching for either in 'xyzABCxyz' works just fine, but in 'xyzABCDExyz' all I get is 'ABC'.
My question is: what should I do to make regex not stop at finding the shortest substring? All that comes to my mind is to change the substrings order but I'm looking for something more elegant.