Performing a regex substitution Perl

后端 未结 4 1049
春和景丽
春和景丽 2021-01-27 17:41

Assuming I have the IP 10.23.233.34 I would like to simply swap the 233 for 234. The first, second, and last octet are unknown. The thir

4条回答
  •  無奈伤痛
    2021-01-27 18:14

    Here's an option:

    use strict;
    use warnings;
    
    my $ip = '10.23.233.34';
    
    $ip =~ s/(\d+)(\.\d+)$/($1 == 233 ? $1+1 : $1) . $2/e;
    
    print $ip;
    

    Output:

    10.23.234.34
    

提交回复
热议问题