Perl regular expression to match an IP address

前端 未结 11 1709
独厮守ぢ
独厮守ぢ 2020-12-11 02:52

I have written this code, but it does not work. Can someone point out the issue?

sub match_ip()
{
  my $ip = \"The IP address is 216.108.225.236:60099\";
  i         


        
11条回答
  •  春和景丽
    2020-12-11 03:03

    This might help:

    my $ip = "195.249.61.14";
    
    my @ips = (
        "set protocols bgp group IBGP-RRCL-CUSTOMER neighbor 195.249.61.142",
        "set protocols bgp group IBGP-RRCL-CUSTOMER neighbor 195.249.61.14",
        "set protocols bgp group IBGP-RRCL-CUSTOMER neighbor 195.249.61.141"
    );
    
    foreach (@ips) {
       print "$_\n" if ( /\b$ip\b/ );
    }
    

    Output:

    set protocols bgp group IBGP-RRCL-CUSTOMER neighbor 195.249.61.14
    

提交回复
热议问题