fork download
  1. import re
  2.  
  3. patterns = [
  4. r".*\btic\b",
  5. r".*\btoc\b"
  6. ]
  7.  
  8. lists = [
  9. ["FOO tic FOO", "BAR toc", "FOO BAR"],
  10. ["FOO FOO FOO", "BAR toc", "FOO BAR"],
  11. ["BAR toc", "FOO tic FOO", "FOO BAR"],
  12. ["BAR toc", "FOO tic FOO", "FOO BAR", "this is tic", "and this is toc"]
  13. ]
  14.  
  15. for l in lists:
  16. for pattern in patterns:
  17. filter_list = list(filter(lambda x: re.search(pattern, x), l))
  18. if len(filter_list) > 0:
  19. print("Pattern {} matches: ".format(pattern), filter_list)
  20. break
Success #stdin #stdout 0.03s 9436KB
stdin
Standard input is empty
stdout
Pattern .*\btic\b matches:  ['FOO tic FOO']
Pattern .*\btoc\b matches:  ['BAR toc']
Pattern .*\btic\b matches:  ['FOO tic FOO']
Pattern .*\btic\b matches:  ['FOO tic FOO', 'this is tic']