const regex = /\!\ninterface\W[A-Z].*Ethernet(\d)\/(\d)([^\!]*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\!\\ninterface\\W[A-Z].*Ethernet(\\d)\\\/(\\d)([^\\!]*)', 'gm')
const str = `Building configuration...
Current configuration : 3058 bytes
!
version 12.2
no service pad
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname cisco.test
!
boot-start-marker
boot-end-marker
!
!
username cisco password 0 cisco
!
!
aaa new-model
!
!
aaa authentication login default local enable
!
!
!
aaa session-id common
system mtu routing 1500
ip routing
no ip domain-lookup
ip domain-name cisco.test
ip dhcp excluded-address 172.29.1.200
ip dhcp excluded-address 172.29.1.1
!
ip dhcp pool USERS
network 172.29.1.0 255.255.255.0
default-router 172.29.1.1
!
!
!
!
crypto pki trustpoint TP-self-signed-508261888
enrollment selfsigned
subject-name cn=IOS-Self-Signed-Certificate-508261888
revocation-check none
rsakeypair TP-self-signed-508261888
!
!
crypto pki certificate chain TP-self-signed-508261888
certificate self-signed 01
3082023D 308201A6 A0030201 02020101 300D0609 2A864886 F70D0101 04050030
30312E30 2C060355 04031325 494F532D 53656C66 2D536967 6E65642D 43657274
69666963 6174652D 35303832 36313838 38301E17 0D393330 33303130 30303130
335A170D 32303031 30313030 30303030 5A303031 2E302C06 03550403 1325494F
532D5365 6C662D53 69676E65 642D4365 72746966 69636174 652D3530 38323631
38383830 819F300D 06092A86 4886F70D 01010105 0003818D 00308189 02818100
DAB963DF 1F90F0D1 0C422912 0788DC49 A3908659 CE3E9610 433233A5 1B1E00F5
3941C9E6 B9FC37C4 F1D39723 282E38FC E03A0384 9C386E0A 380FCE52 B77A1A69
F62F2E8B FB570F83 3F0CDD21 058BE6BD A1B8BE37 4AFD3B02 E339CBA9 EB073555
63358466 8C7CFF88 D0F562CC B6C6CC0D 981CAB30 CB7CA2E5 CDD17A21 5AEC6F09
02030100 01A36730 65300F06 03551D13 0101FF04 05300301 01FF3012 0603551D
11040B30 09820753 77697463 682E301F 0603551D 23041830 16801460 F6485305
D274086D F29F51DE A3659656 752BB730 1D060355 1D0E0416 041460F6 485305D2
74086DF2 9F51DEA3 65965675 2BB7300D 06092A86 4886F70D 01010405 00038181
00590208 E0E292D7 B18ABD77 3D781313 A70B7896 46EE9079 1C66D967 B01D078C
A420A1D5 FE4C7CA9 EA89BC95 D0F2B0A4 4298B12C 3AB2DDC3 7608BD34 3FB41615
6833E4C3 52BDFDA2 DF7C4C9A B94A4745 386E8DB0 C4EB298A D5B00560 490EA5AF
5B357860 E01D60F2 D9DBD62F 0922DF2B 11039A71 B23064EC CB4C846E DCCCDC4B A4
quit
!
!
!
spanning-tree mode pvst
spanning-tree extend system-id
!
vlan internal allocation policy ascending
!
ip ssh time-out 60
ip ssh authentication-retries 2
ip ssh version 2
!
!
interface FastEthernet0/1
switchport mode access
switchport port-security
switchport port-security mac-address sticky
shutdown
!
interface FastEthernet0/2
!
interface FastEthernet0/3
!
interface FastEthernet0/4
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface GigabitEthernet0/1
!
interface Vlan1
ip address 172.29.1.200 255.255.255.0
!
ip classless
ip http server
ip http secure-server
!
!
!
line con 0
length 0
line vty 0 4
privilege level 15
logging synchronous
length 0
transport input ssh
line vty 5 15
privilege level 15
logging synchronous
length 0
transport input ssh
!
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions