You can use a negative lookahead before the description of the lines after the ip address:
(?m)^interface .*(\n(?!!).*)*?(.*ip address.*)(\n(?!.*no cdp enable)(?!!).*)*\n!
Pregunta
I'm trying to figure out reg-ex to solve a problem.
I'm working with an app that uses reg-ex and it chops up cisco configs at the interface level.
I need a reg-ex that will match when there is an IP address and not a line of no cdp enable.
so, I've tried:
ip address .*\n\s+(?=no cdp enable)
Some configs will have an IP address line and no 'no cdp enable' line, some will have both, some will just have the 'no cdp enable', etc.
Example should be a match:
interface Ethernet0/0
description abcd
ip address 192.168.1.85 255.255.255.0
no ip route-cache
no ip mroute-cache
half-duplex
!
Example should not be a match (it has the no cdp enable line):
interface FastEthernet1/0
description xxxxxx
ip address 10.10.10.1 255.255.255.0
no ip route-cache
no ip mroute-cache
half-duplex
no cdp enable
!
Example should not be a match (no IP address, has no cdp enable):
interface Serial0
description test
no ip route-cache
no ip mroute-cache
half-duplex
no cdp enable
!
Anyone have any ideas / see where my statement is breaking down?
Solución
You can use a negative lookahead before the description of the lines after the ip address:
(?m)^interface .*(\n(?!!).*)*?(.*ip address.*)(\n(?!.*no cdp enable)(?!!).*)*\n!