Reputation: 33
Hello i have problem with this regexp
!
interface TenGigabitEthernet 1/49
description Uplink
no ip address
switchport
no shutdown
!
interface TenGigabitEthernet 1/50
no ip address
shutdown
!
interface TenGigabitEthernet 1/51
no ip address
shutdown
!
i tried this regexp (interface) ((.\s.)+) but it is not working becuse it match "interface" and the rest of text
I need to catch in first group "interface" and in the second i need all until first occur of "!" so for example: first group:
interface
second group:
TenGigabitEthernet 1/51
no ip address
shutdown
How i can do this?
Upvotes: 3
Views: 57
Reputation: 163457
If the content itself can contain a !
, you could check for a !
at the start of the line and repeat matching all lines until you encounter a !
at the start.
^(interface)\s*(.*(?:\n(?!!).*)*)
In Java
String regex = "^(interface)\\s*(.*(?:\\n(?!!).*)*)";
Upvotes: 0