fork download
  1. import re
  2.  
  3. def all_matching(s, pat):
  4. return pat.search(s)
  5.  
  6. input1 = """DIR1\\FILE1.EXT1\tCONTENT11
  7. DIR1\\FILE1.EXT1\tCONTENT12
  8. DIR1\\FILE1.EXT1\tCONTENT13
  9. DIR1\\FILE2.EXT1\tCONTENT21
  10. DIR2\\FILE3.EXT2\tCONTENT31
  11. DIR3\\FILE3.EXT2\tCONTENT11"""
  12.  
  13. input2 = """DIR1\\FILE1.EXT1\tCONTENT11
  14. DIR1\\FILE1.EXT1\tCONTENT12
  15. DIR1\\FILE1.EXT1\tCONTENT13
  16. DIR1\\FILE2.EXT1\tCONTENT21
  17. DIR2\\FILE3.EXT2\tCONTENT31"""
  18.  
  19. rxs = [r"^\S*FILE1\S*\tCONTENT11$",r"^\S*FILE1\S*\tCONTENT12$",r"^\S*FILE3\S*\tCONTENT11$"]
  20. pat = re.compile( r"(?m)\A(?=(?:.*\n)*?{})".format(r")(?=(?:.*\n)*?".join([rx[1:] for rx in rxs])) )
  21. print(pat.pattern)
  22.  
  23. if all_matching(input1,pat):
  24. print("input1 matches all rxs") # excpected
  25. else:
  26. print("input1 do not match all rxs")
  27.  
  28. if all_matching(input2,pat):
  29. print("input2 matches all rxs")
  30. else:
  31. print("input2 do not match all rxs") # expected because input2 doesn't match wirh rxs[2]
Success #stdin #stdout 0.03s 9528KB
stdin
Standard input is empty
stdout
(?m)\A(?=(?:.*\n)*?\S*FILE1\S*\tCONTENT11$)(?=(?:.*\n)*?\S*FILE1\S*\tCONTENT12$)(?=(?:.*\n)*?\S*FILE3\S*\tCONTENT11$)
input1 matches all rxs
input2 do not match all rxs