def match_consecutive(needles, haystack, ignore_case=False):
 regex_no_sep = (('[^' + os.sep) + ']*')
 regex_no_sep_end = (regex_no_sep + '$')
 regex_one_sep = ((regex_no_sep + os.sep) + regex_no_sep)
 regex_needle = (regex_one_sep.join(imap(re.escape, needles)) + regex_no_sep_end)
 regex_flags = ((re.IGNORECASE | re.UNICODE) if ignore_case else re.UNICODE)
 found = (lambda entry: re.search(regex_needle, entry.path, flags=regex_flags))
 return ifilter(found, haystack)

def match_consecutive ( needles , haystack , ignore_case = False ) : regex_no_sep = ( ( '[^' + os . sep ) + ']*' ) regex_no_sep_end = ( regex_no_sep + '$' ) regex_one_sep = ( ( regex_no_sep + os . sep ) + regex_no_sep ) regex_needle = ( regex_one_sep . join ( imap ( re . escape , needles ) ) + regex_no_sep_end ) regex_flags = ( ( re . IGNORECASE | re . UNICODE ) if ignore_case else re . UNICODE ) found = ( lambda entry : re . search ( regex_needle , entry . path , flags = regex_flags ) ) return ifilter ( found , haystack )
matches consecutive needles at the end of a path .