I need help with this python regex

Ed Manning ejmmanning at gmail.com
Sat Apr 28 00:04:49 EDT 2018


Here is the source code.


import re


log = open("csg.txt", "r") # Opens a file call session.txt
regex = re.compile(r'policy id \d+') # search for the policy ID
regex1 = re.compile(r'log count \d+') # search for the policy ID

for match in log:
    x = regex.findall(match)
    y = regex1.findall(match)

    q = x + y
    print(q)
 

The problem I am having i when it print out ti looks like this


L'Policy ID 243"|
[]
[]
[]
[]
[]
[]
[]
[]
{'log count 777,"]



How so I fix the code sone that it does not print empty []






Here so to the test file 


 get policy id 243
name:"csg to wes" (id 243), zone csg -> fwc,action Permit, status "enabled"
10 sources: "206.221.59.229", "206.221.59.246/32", "csg_205.144.151.107/32", "csg_205.144.151.177/32", "csg_205.144.151.24/32", "csg_205.144.152.50/32", "csg_205.144.153.55/32", "csg_206.221.59.244/32", "csg_206.221.59.250/32", "csg_206.221.61.29/32"
19 destinations: "MIP(204.235.119.135)", "MIP(204.235.119.136)", "MIP(204.235.119.243)", "MIP(204.235.119.34)", "MIP(204.235.119.39)", "MIP(204.235.119.40)", "MIP(204.235.119.41)", "MIP(204.235.119.42)", "MIP(204.235.119.43)", "MIP(204.235.119.44)", "MIP(204.235.119.45)", "MIP(204.235.119.46)", "MIP(204.235.119.47)", "MIP(204.235.119.50)", "MIP(204.235.119.51)", "MIP(204.235.119.52)", "MIP(204.235.119.79)", "MIP(204.235.119.82)", "MIP(204.235.119.83)"
1 service: "ANY"
Rules on this VPN policy: 0
nat off, Web filtering : disabled
vpn unknown vpn, policy flag 00010000, session backup: on
traffic shaping off, scheduler n/a, serv flag 00
log close, log count 777, alert no, counter yes(79) byte rate(sec/min) 0/0
total octets 0, counter(session/packet/octet) 0/0/79
priority 7, diffserv marking Off
tadapter: state off, gbw/mbw 0/0 policing (no)
No Authentication
No User, User Group or Group expression se
 get policy id 602
name:"ID 36129" (id 602), zone csg -> fwc,action Permit, status "enabled"
src "csg_205.144.151.107/32", dst "MIP(204.235.119.191)", serv "ANY"
Rules on this VPN policy: 0
nat off, Web filtering : disabled
vpn unknown vpn, policy flag 00010000, session backup: on
traffic shaping off, scheduler n/a, serv flag 00
log close, log count 0, alert no, counter yes(80) byte rate(sec/min) 0/0
total octets 0, counter(session/packet/octet) 0/0/80
priority 7, diffserv marking Off
tadapter: state off, gbw/mbw 0/0 policing (no)
No Authentication
No User, User Group or Group expression set
csg-vx-fw-n-12:csg-vx-fw-n-01(M)-> get policy id 420
name:"ID 12637" (id 420), zone csg -> fwc,action Permit, status "enabled"
1 source: "csg_204.235.119.78/32"
1 destination: "eg_csg"
6 services: "PING", "tcp_30001-30100", "tcp_6051-6055", "tcp_7041-7091", "TELNET", "TRACEROUTE"
Rules on this VPN policy: 0
nat off, Web filtering : disabled
vpn unknown vpn, policy flag 00010000, session backup: on
traffic shaping off, scheduler n/a, serv flag 00
log close, log count 0, alert no, counter yes(81) byte rate(sec/min) 0/0
total octets 0, counter(session/packet/octet) 0/0/81
priority 7, diffserv marking Off
tadapter: state off, gbw/mbw 0/0 policing (no)
No Authentication
No User, User Group or Group expression set



More information about the Python-list mailing list