Regex To Include And Exclude Certain Ips
I have a functional python 2.7 code that extracts IPs from the routing table. It only extracts ip in x.x.x.x/xx format. I do however has a issue excluding some lines in the route
Solution 1:
If I got your question correctly you want your existing regex to skip any IP/subnet that is followed by 'is variably subnetted'. Do that that you can use this regex:
(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\/(?:[\d]{1,3})\b(?! is variably)
- I've added
\b(?! is variably)
at the end of your regex \b
at the end indicates a word boundary(?! is variably)
has a negative lookahead(?!
which makes sure that the text ' is variably' isn't present after the IP/subnet.
Demo: https://regex101.com/r/jTu8cj/1
Matches:
D 10.50.80.0/24 [90/3072] via 10.10.10.1, 3w6d, Vlan10
C 10.10.140.0/24is directly connected, Vlan240
Doesn't match:
10.10.60.0/16is variably subnetted, 58 subnets, 4 masks
255.255.255.1
Post a Comment for "Regex To Include And Exclude Certain Ips"