Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression : Multiline check problem

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?

like image 309
Lukasz Flak Avatar asked Dec 03 '25 09:12

Lukasz Flak


2 Answers

Try this:

(interface)\s+([^!]+)

Here Is Demo

Use this:

(interface)\s*([^!]+) /g

The first group captures the hard-coded interface. The second group captures everything other than !, by skipping the leading whitespaces, if any. The global flag /g ensures all matches.

Demo

like image 45
CinCout Avatar answered Dec 04 '25 22:12

CinCout