content = ''' abcdefg hijklmn opq rst uvw xyz ''' r = re.compile('S+cdeS+|S+klmS+|^xyz$', re.MULTILINE) r.findall(content) ['abcdefg', 'hijklmn', 'xyz']