有没有办法做可选或可选的?我想将这些接口作为group1的一部分进行匹配。
interface GigabitEthernet3/11
interface GigabitEthernet2/2
interface GigabitEthernet2/3
text is here:
interface GigabitEthernet2/1
description test
switchport access vlan 102
switchport mode access
switchport voice vlan 202
no logging event link-status
no logging event power-inline-status
no snmp trap link-status
spanning-tree portfast edge
spanning-tree guard root
!
interface GigabitEthernet2/4
description User
switchport access vlan 102
switchport mode access
no logging event link-status
no logging event power-inline-status
no snmp trap link-status
spanning-tree portfast edge
spanning-tree guard root
!
interface GigabitEthernet2/4
description User
switchport access vlan 102
no logging event link-status
no logging event power-inline-status
no snmp trap link-status
spanning-tree portfast edge
spanning-tree guard root
!
interface GigabitEthernet3/11
switchport trunk allowed vlan 102,202
switchport trunk native vlan 102
switchport mode access
switchport voice vlan 202
spanning-tree portfast edge trunk
spanning-tree guard root
!
interface GigabitEthernet2/2
description User
switchport mode access
no logging event link-status
no logging event power-inline-status
no snmp trap link-status
spanning-tree portfast edge
spanning-tree guard root
!
interface GigabitEthernet2/3
switchport voice vlan 202
no logging event link-status
no logging event power-inline-status
no snmp trap link-status
spanning-tree portfast edge
spanning-tree guard root
!我的正则表达式:
(interface [A-Za-z]+\d\/\S+)\n(?:^\s.*|\n)*(switchport access vlan\s(\d+))|(switchport mode access)|(switchport voice vlan.*)发布于 2021-08-18 19:41:58
如果你只是在寻找一种方法来捕获所有的“交换端口”
在单个接口记录中,下面只添加不同的接口记录
交替(如你所说的)。
只需根据需要添加更多或开关端口项即可。
以下内容恰好是以一种无序的方式获取所有相关项目的。
这也将考虑到任何交织,如果它发生。
(?im)^(interface[ ][A-Za-z\d]+\/\S+)(?:\s*(?:^(?!(?:interface|!)).*\s+)*?[ \t]+(?:(switchport[ \t]+access[ \t]+vlan[ \t]+(\d+))|(switchport[ \t]+voice[ \t]+vlan)|(switchport[ \t]+mode[ \t]+access)).*)*https://regex101.com/r/rjzC4y/1
(?im)
^
( interface [ ] [A-Za-z\d]+ \/ \S+ ) # (1)
(?:
\s*
(?:
^
(?!
(?: interface | ! )
)
.* \s+
)*?
[ \t]+
(?:
( # (2 start)
switchport [ \t]+ access [ \t]+ vlan [ \t]+
( \d+ ) # (3)
) # (2 end)
| ( switchport [ \t]+ voice [ \t]+ vlan ) # (4)
| ( switchport [ \t]+ mode [ \t]+ access ) # (5)
# Add more switchport types here
)
.*
)*https://stackoverflow.com/questions/68833159
复制相似问题