# filter a list by checking if substring of another list is contained in entries of the list to be filtered # here flags is some list which contain entries from the list regex --> filter matching regex from list flags flags = ['"s/regex/looking/g"', 'options', '"s/another/regex/"', '--more flags'] regex = [unquote(flag) for flag in flags if unquote(flag).startswith('s/')] flags = [flag for flag in flags if not any(flag for reg in regex if reg in flag)]