Not to anger the Python gods, but I need an explanation on something that works. I'm working through the output of ARP tables in Cisco routers. I'm filtering everything before the IP address and after the MAC address. (Easy) Then I needed to filter out the ARP Age in-between the IP & MAC. This could and varying number of spaces followed by a hyphen or 1 to 3 digits then more spaces.
I was catching the hyphen or a single digit, but never 2 or 3 digits and the surrounding spaces. I had to put in pattern 4 to make it work. Shouldn't the \d+ in strPattern3 catch [spaces][hyphen or digits][spaces]?
strPattern3 = re.compile('(\s+[-\d+]\s+)') #Catch any spaces then a hypen or digits followed by spaces (ARP age)
strPattern4 = re.compile('(\s+\d+\s+)') #Catch any spaces then any digits then any more spaces (ARP age)
szResult = strPattern3.sub('\t', szResult)
szResult = strPattern4.sub('\t', szResult)
SAMPLE ARP TABLE
Internet 10.241.130.14 159 f0d5.bf04.e3b8 ARPA GigabitEthernet0/0.20
Internet 10.241.130.17 1 ecf4.bb6b.918a ARPA GigabitEthernet0/0.20
Internet 10.241.130.19 47 f01f.af10.7a45 ARPA GigabitEthernet0/0.20
Internet 10.241.130.20 0 5475.d0ab.a86c ARPA GigabitEthernet0/0.20
Internet 159.142.132.97 - 6073.5cc5.6598 ARPA GigabitEthernet0/0.20