Henrique Mota:
La salida que tengo es la siguiente:
T 2020/03/05 16:06:41.565817 193.126.13.199:80 -> 10.8.0.4:55639 [AP] HTTP/1.1 200 OK..Date: Thu, 05 Mar 2020 16:06:41 GMT..Server: Apache/2.2.3 (CentOS)..Expires: Thu, 19 Nov 1981 08:52:00 GMT..Cache-Control: no-store, no-cache,
T 2020/03/05 16:06:46.727199 10.8.0.4:55642 -> 193.126.13.199:80 [AP] GET / HTTP/1.1..Host: www.radionova.fm..User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/xml;q=0.9,image/webp,*/*;q=0.8..Accept-Langu
T 2020/03/05 16:06:47.174078 193.126.13.199:80 -> 10.8.0.4:55642 [A] HTTP/1.1 200 OK..Date: Thu, 05 Mar 2020 16:06:46 GMT..Server: Apache/2.2.3 (CentOS)..Expires: Thu, 19 Nov 1981 08:52:00 GMT..Cache-Control: no-store, no-cache
¿Cómo puedo hacer un patrón de expresión regular para que coincida con sólo las filas [AP]?
Algo como:
T 03/05/2020 16: 06: 46.727199 10.8.0.4:55642 -> 193.126.13.199:80 [AP] GET / HTTP / 1.1..Host: www.radionova.fm..User-Agent: Mozilla / 5.0 ( Macintosh, Intel Mac OS X 10.15; rv: 72.0)
Así que .. el primer grupo: 03/05/2020
Segundo grupo: 16: 06: 46.727199
Tercer grupo: 10.8.0.4:55642
Cuarto grupo: GET / HTTP / 1.1..Host: www.radionova.fm..User-Agent: Mozilla / 5.0 (Macintosh; Intel Mac OS X 10.15; rv: 72.0)
Tengo la siguiente expresión regular pitón:
pattern = r'''T\s([^ ]+)\s([^ ]+)\s([^ ]+).*?[.]{2,}(.*?)[.]{2,}'''
No funciona como yo quiero ..
Ene :
¿Por qué no lo obvio in
operador?
data = """
T 2020/03/05 16:06:41.565817 193.126.13.199:80 -> 10.8.0.4:55639 [AP] HTTP/1.1 200 OK..Date: Thu, 05 Mar 2020 16:06:41 GMT..Server: Apache/2.2.3 (CentOS)..Expires: Thu, 19 Nov 1981 08:52:00 GMT..Cache-Control: no-store, no-cache,
T 2020/03/05 16:06:46.727199 10.8.0.4:55642 -> 193.126.13.199:80 [AP] GET / HTTP/1.1..Host: www.radionova.fm..User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/xml;q=0.9,image/webp,*/*;q=0.8..Accept-Langu
T 2020/03/05 16:06:47.174078 193.126.13.199:80 -> 10.8.0.4:55642 [A] HTTP/1.1 200 OK..Date: Thu, 05 Mar 2020 16:06:46 GMT..Server: Apache/2.2.3 (CentOS)..Expires: Thu, 19 Nov 1981 08:52:00 GMT..Cache-Control: no-store, no-cache
"""
rows_ap = [(splitted[1], splitted[2], splitted[3], " ".join(splitted[7:]))
for line in data.split("\n")
if line and "[AP]" in line
for splitted in [line.split(" ")]]
print(rows_ap)