I want to match lines that start with a specific string (in this example "interface") if there is a another defined text (here "switchport mode access") in the following indented lines.
Example data:
interface GigabitEthernet1/0/1
description abc
bla
switchport mode access
xyz
abc
interface GigabitEthernet1/0/2
interface GigabitEthernet1/0/3
xyz
abc
interface GigabitEthernet1/0/4
description Test
switchport mode access
xyz
abc
interface GigabitEthernet1/0/5
description
Should match:
interface GigabitEthernet1/0/1
interface GigabitEthernet1/0/4
I tried:
interface GigabitEthernet1\/0\/[0-9](?=(\n|.)*switchport mode access)
But this checks all the lines below an interface, so it does match:
interface GigabitEthernet1/0/1
interface GigabitEthernet1/0/2
interface GigabitEthernet1/0/3
interface GigabitEthernet1/0/4
How can I make the lookahead only work until there is a line that doesnt start with a whitespace?