fork download
  1. import re
  2.  
  3. regex = r"^(?P<date>\d+/\d+/\d+) (?P<time>\d{2}:\d{2}:\d{2} [AP]M).*? (?P<client>(?:[0-9]{1,3}\.){3}[0-9]{1,3}).*?] (?P<flags>.{1,4}).*? (?P<query>\S*)$"
  4.  
  5. test_str = ("4/19/2020 11:59:09 PM 2604 PACKET 0000014DE1921330 UDP Rcv 192.168.1.28 f975 Q [0001 D NOERROR] A (7)pagead2(17)googlesyndication(3)com(0)\n"
  6. "4/19/2020 11:59:09 PM 0574 PACKET 0000014DE18C4720 UDP Rcv 192.168.2.54 9c63 Q [0001 D NOERROR] A (2)pg(3)cdn(5)viber(3)com(0)")
  7. print(re.findall(regex, test_str, re.M))
Success #stdin #stdout 0.02s 9580KB
stdin
Standard input is empty
stdout
[('4/19/2020', '11:59:09 PM', '192.168.1.28', 'A   ', '(7)pagead2(17)googlesyndication(3)com(0)'), ('4/19/2020', '11:59:09 PM', '192.168.2.54', 'A   ', '(2)pg(3)cdn(5)viber(3)com(0)')]