import re
DATA = 'QUWESEADFQDFSAEDFS'
substrings = re.findall('Q([^E]+)E', DATA)
print('Substrings:', substrings)
substrings.sort(key=lambda s: len(s))
print('Shortest substring:', substrings[0])
finding substrings in python