我正在尝试确定我在cisco路由器上放置的命令是否只有以下输出中的邻居条目..
我有以下正则表达式..如果搜索到达结尾但未找到第二个匹配项,如何使搜索失败?
if (! $document =~/(Device\sID)(.*?)(Device\sID)/s){
print("Theres no double entries\n");
} else {
print ("double!\n");
}
Device ID: NAME1
Entry address(es):
IP address: IP.IP.IP.IP
Plautform: cisco WS-C3850-48T, Capabilities: Switch IGMP
Interface: GigabitEthernet1/x, Port ID (outgoing port): GigabitEthernetx/x/x
Holdtime : 123 sec
Version :
Cisco IOS Software, IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 03.02.03.SE RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2013 by Cisco Systems, Inc.
Compiled Mon 23-Sep-13 18:24 by prod_rel_team
advertisement version: 2
VTP Management Domain: 'NAME1'
Native VLAN: 1
Duplex: full
Management address(es):
IP address: IP.IP.IP.IP
此致 彼得
答案 0 :(得分:0)
!~
是正则表达式不匹配的运算符。
$document !~ /(Device\sID)(.*?)(Device\sID)/s
答案 1 :(得分:0)
您遇到运营商优先问题。 !
的优先级高于=~
,因此您的表达式为:
if ( ! $document =~ /(Device\sID)(.*?)(Device\sID)/s ) {
与:
相同 if ( (! $document) =~ /(Device\sID)(.*?)(Device\sID)/s ) {
但你想:
if ( ! ($document =~ /(Device\sID)(.*?)(Device\sID)/s) ) {
与以下内容相同:
if ( $document !~ /(Device\sID)(.*?)(Device\sID)/s ) {